Merge pull request #2624 from geekpi/master

translated
This commit is contained in:
geekpi 2015-04-14 10:22:19 +08:00
commit ec66af2b2b
2 changed files with 73 additions and 75 deletions

View File

@ -1,75 +0,0 @@
Translating----geekpi
Linux FAQs with Answers--How to change PATH environment variable on Linux
================================================================================
> **Question**: When I try to run an executable, it complains "command not found." The executable is actually located in /usr/local/bin. How can I add /usr/local/bin to my PATH variable, so that I can run the command without specify the path?
In Linux, PATH environment variable stores a set of directories to search for an executable command when the command is typed by a user. The value of PATH variable is formatted as a series of colon-separated absolute paths. Each user has a user-specific PATH environment variable (initialized with system-wide default PATH variable).
To check the current PATH environment variable of a user, run the following command as the user:
$ echo $PATH
----------
/usr/lib64/qt-3.3/bin:/bin:/usr/bin:/usr/sbin:/sbin:/home/xmodulo/bin
Alternatively, run:
$ env | grep PATH
----------
PATH=/usr/lib64/qt-3.3/bin:/bin:/usr/bin:/usr/sbin:/sbin:/home/xmodulo/bin
If the command that you type is not found in any of these directories, the shell will throw an error message: "command not found"
If you want to add an additional directory (e.g., /usr/local/bin) to your PATH variable, you can follow these instructions.
### Change PATH Environment Variable for a Particular User Only ###
If you want to temporarily add a new directory (e.g., /usr/local/bin) to a user's default search path in the current login session, you can simply type the following.
$ PATH=$PATH:/usr/local/bin
Now check if PATH has been updated:
$ echo $PATH
----------
/usr/lib64/qt-3.3/bin:/bin:/usr/bin:/usr/sbin:/sbin:/home/xmodulo/bin:/usr/local/bin
The updated PATH will then remain effective in the current login session. The change, however, will be lost in any new terminal session.
If you want to change PATH variable permanently, open ~/.bashrc (or ~/.bash_profile) with a text editor, and append the following line.
export PATH=$PATH:/usr/local/bin
Then activate the change permanently by running:
$ source ~/.bashrc (or source ~/.bash_profile)
### Change PATH Environment Variable System-wide ###
If you want to permanently add /usr/local/bin to system-wide default PATH variable, edit /etc/profile as follows.
$ sudo vi /etc/profile
----------
export PATH=$PATH:/usr/local/bin
Once you re-login, the updated PATH variable will take effect.
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/change-path-environment-variable-linux.html
作者:[Dan Nanni][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://ask.xmodulo.com/author/nanni

View File

@ -0,0 +1,73 @@
Linux有问必答--如何在Linux中修改环境变量PATH
================================================================================
> **提问**: 当我试着运行一个程序时它提示“command not found”。 但这个程序就在/usr/local/bin下。我该如何添加/usr/local/bin到我的PATH变量下这样我就可以不用指定路径来运行这个命令了。
在Linux中PATH环境变量保存了一系列的目录用于用户在输入的时候搜索命令。PATH变量的值由一系列的由分号分隔的绝对路径组成。每个用户都有特定的PATH环境变量由系统级的PATH变量初始化
要检查用户的环境变量,用户模式下运行下面的命令:
$ echo $PATH
----------
/usr/lib64/qt-3.3/bin:/bin:/usr/bin:/usr/sbin:/sbin:/home/xmodulo/bin
或者运行:
$ env | grep PATH
----------
PATH=/usr/lib64/qt-3.3/bin:/bin:/usr/bin:/usr/sbin:/sbin:/home/xmodulo/bin
如果你的命令不存在于上面任何一个目录内shell就会抛出一个错误信息“command not found”。
如果你想要添加一个另外的目录(比如:/usr/local/bin到你的PATH变量中你可以用下面这些命令。
### 为特定用户修改PATH环境变量 ###
如果你只想在当前的登录会话中临时地添加一个新的目录(比如:/usr/local/bin给用户的默认搜索路径你只需要输入下面的命令。
$ PATH=$PATH:/usr/local/bin
检查PATH是否已经更新
$ echo $PATH
----------
/usr/lib64/qt-3.3/bin:/bin:/usr/bin:/usr/sbin:/sbin:/home/xmodulo/bin:/usr/local/bin
更新的PATH会在当前的PATH一直有效。然而更改将在新的会话中失效。
如果你想要永久更改PATH变量用编辑器打开~/.bashrc (或者 ~/.bash_profile),接着在最后添加下面这行。
export PATH=$PATH:/usr/local/bin
接着运行下面这行永久激活更改:
$ source ~/.bashrc (or source ~/.bash_profile)
### 改变系统级的环境变量 ###
如果你想要永久添加/usr/local/bin到系统级的PATH变量中像下面这样编辑/etc/profile。
$ sudo vi /etc/profile
----------
export PATH=$PATH:/usr/local/bin
你重新登录后,更新的环境变量就会生效了。
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/change-path-environment-variable-linux.html
作者:[Dan Nanni][a]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://ask.xmodulo.com/author/nanni