如何在 $PATH 变量 linux 中添加多个路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21131590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:51:37  来源:igfitidea点击:

How to add multiple path in $PATH variable linux?

linuxpath

提问by user3086014

I want to add multiple path in $path variable like java path and php path . how to do that in linux?

我想在 $path 变量中添加多个路径,如 java path 和 php path 。如何在 linux 中做到这一点?

I am doing something in bash_profile like :

我正在 bash_profile 中做一些事情,例如:

PATH=$JAVA_HOME/bin:$PATH:/usr/java/jdk1.7.0_45/bin/:$AWS_AUTO_SCALING_HOME/bin 

回答by Mureinik

$PATHcan have several paths separated by a colon (:). E.g.:

$PATH可以有多个路径以冒号 ( :)分隔。例如:

export PATH=/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/myuser/bin

回答by user3135746

Set the $PATHenvironment variable to include the directory where you installed the bin directory with shell scripts and two consecutive export entries as in example.

$PATH环境变量设置为包含您安装 bin 目录的目录,其中包含 shell 脚本和两个连续的导出条目,如示例中所示。

Example:

示例

export ANT_HOME=/path/to/ant/dir
export PATH=${PATH}:${ANT_HOME}/bin:${JAVA_HOME}/bin

To make them permanent entries update the bash_profile file.

要使它们成为永久条目,请更新 bash_profile 文件。

回答by user3135746

One way to add multiple executables to the $PATH variable is:

将多个可执行文件添加到 $PATH 变量的一种方法是:

export PATH=/path/to/executable1:\
/path/to/executable2:\
/path/to/executable3:\
/path/to/executable4

If a $PATHalready exists in .bash_profile, and you want them to take precedence over executables(like java and php), you can do:

如果 a$PATH已存在于 中.bash_profile,并且您希望它们优先于可执行文件(如 java 和 php),您可以执行以下操作:

export PATH=$PATH:/path/to/executable1:\
/path/to/executable2:\
/path/to/executable3:\
/path/to/executable4

If the path to any executable contains whitespaces, add the part / ... executableXin quotes.

如果任何可执行文件的路径包含空格,请/ ... executableX在引号中添加该部分。

Once you're done making changes in your bash_profile, source the file in a terminal session so that changes are effective immediately:

完成更改后bash_profile,在终端会话中获取文件,以便更改立即生效:

source .bash_profile