Linux .bashrc 中究竟在哪里设置 PATH?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18302019/
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
Where exactly in .bashrc set PATH?
提问by cpp
At the end of .bashrc file I added these lines to set path to foo
folder in my home directory:
在 .bashrc 文件的末尾,我添加了这些行来设置foo
我的主目录中文件夹的路径:
PATH = $PATH:/home/username/foo
export PATH;
Then I typed in bash:
然后我输入bash:
source .bashrc
These produced error:
这些产生了错误:
bash: PATH: command not found
I am using Debian Squeeze. In a similar question hereit was advised to modify /etc/login.defs. I don't want to do this as in the very login.defs it is written:
我正在使用 Debian Squeeze。在一个类似的问题在这里有人建议修改/etc/login.defs的。我不想像在 login.defs 中那样这样做:
add the rest [of your paths] in the shell startup files
How to add folder foo
to PATH in .bashrc?
如何foo
在 .bashrc中将文件夹添加到 PATH?
采纳答案by nmaier
You are using the wrong syntax. Drop the spaces:
您使用了错误的语法。删除空格:
export PATH=$PATH:/home/username/foo
Regarding /etc/login.defs
or any other global configuration: Well, it is global configuration, so probably a bad idea to add paths within your $HOME
directory there. ;)
关于/etc/login.defs
或任何其他全局配置:嗯,这是全局配置,因此在您的$HOME
目录中添加路径可能是个坏主意。;)
回答by MSM
Just use the following line in your .bashrc
只需在 .bashrc 中使用以下行
export PATH=/home/username/foo:$PATH
回答by Ayush Kumar Sharma
There are differences in syntax between the one used on mac and CentOS, however on CentOS and RedHat the following syntax is being used.
在 mac 和 CentOS 上使用的语法之间存在差异,但是在 CentOS 和 RedHat 上使用以下语法。
export PATH="/path/directory:$PATH"
then do
source .bashrc
export PATH="/path/directory:$PATH"
然后做
source .bashrc
I am not sure about other distributions of Linux but it will work on CentOS and RedHat.
我不确定 Linux 的其他发行版,但它可以在 CentOS 和 RedHat 上运行。