bash 'usr/bin' 不包含在路径环境中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40012993/
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
'usr/bin' is not included in the path environment
提问by Daniel
Whenever I start a new terminal and try to run a command, I get this error. I have found out that it can be solved with export PATH=/usr/bin:/bin, but it has to be done for each terminal I open. In the etc/environment file, the path is correct, so hence I do not understand what is wrong.(But this error appeared after I added some lines to bashrc and paths to have some shortcuts for ruby, rails , git ; ( was following a course on Coursera )). How can this be fixed?
每当我启动一个新终端并尝试运行命令时,我都会收到此错误。我发现它可以通过 export PATH=/usr/bin:/bin 解决,但必须为我打开的每个终端完成。在 etc/environment 文件中,路径是正确的,因此我不明白出了什么问题。(但是在我向 bashrc 和路径添加了一些行以提供 ruby、rails、git 的一些快捷方式之后出现了这个错误;(正在关注Coursera 上的一门课程))。如何解决这个问题?
回答by Hyman Bracken
What's happened here is you've clobbered your PATH variable. Your PATH is pretty important, whenever you enter a command your shell (usually bash), will check each of the directories specified in your PATH for a program of the same name.
这里发生的事情是你破坏了你的 PATH 变量。您的 PATH 非常重要,每当您输入命令时,您的 shell(通常是 bash)都会检查 PATH 中指定的每个目录是否有同名程序。
Each directory specified in your path is separated by a colon :
, and a minimal PATH variable usually looks something like /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
.
路径中指定的每个目录都用冒号分隔:
,最小的 PATH 变量通常类似于/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
.
When you have the line export PATH=/usr/bin/git
at the end of your .bashrc
you are telling your shell that you only want to search /usr/bin/git
for commands.
当您export PATH=/usr/bin/git
在末尾有一行时,.bashrc
您是在告诉您的 shell 您只想搜索/usr/bin/git
命令。
Instead, the line export PATH="$PATH:/usr/bin/git"
will tell your shell to search all of the directories previously specified in your shell, and then search /usr/bin/git
.
相反,该行export PATH="$PATH:/usr/bin/git"
会告诉您的 shell 搜索先前在您的 shell 中指定的所有目录,然后搜索/usr/bin/git
.
Another thing to note is that your shell will search the directories in your PATH in the order they're specified, and use the first matching command found, so the order that directories are specified in the PATH can matter too.
另一件要注意的事情是,您的 shell 将按照指定的顺序搜索 PATH 中的目录,并使用找到的第一个匹配命令,因此在 PATH 中指定目录的顺序也很重要。