question : When I try to run a program, it prompts "command not found". But this program is under/usr/local/bin. How do I add/usr/local/bin to my path variable so that I can run the command without specifying a path.
In Linux, the PATH environment variable holds a series of directories for the user to search for commands at the time of input. The value of the path variable consists of a series of absolute paths separated by semicolons. Each user has a specific PATH environment variable (initialized by the system-level path variable).
To check the user's environment variables, run the following command in user mode:
$ echo $PATH
/usr/lib64/qt-3.3/bin:/bin:/usr/bin:/usr/sbin:/sbin:/home/xmodulo/bin
or run:
$ env | grep PATH
PATH=/usr/lib64/qt-3.3/bin:/bin:/usr/bin:/usr/sbin:/sbin:/home/xmodulo/bin
If your command does not exist in any of the above directories, the shell throws an error message: "Command not Found".
If you want to add an additional directory (for example:/usr/local/bin) to your PATH variable, you can use these commands.
To modify the PATH environment variable for a specific user
If you only want to temporarily add a new directory (for example:/usr/local/bin) to the user's default search path in the current login session, you only need to enter the following command.
$ PATH=$PATH:/usr/local/bin
Check if path has been updated:
-
$ echo $PATH
-
/usr/lib64/ qt-3.3/bin :/bin:/usr/bin:/usr/sbin:/sbin:/ home/xmodulo/bin< Span class= "pun" >:/usr/local/bin
The updated path will remain in effect for the current session. However, the changes will expire in the new session.
If you want to permanently change the path variable, open ~/.BASHRC (or ~/.bash_profile) with the editor and add the following line at the end.
export PATH=$PATH:/usr/local/bin
Then run the following line to permanently activate the changes:
$ source ~/.bashrc (或者 source ~/.bash_profile)
Changing the environment variables at the system level
If you want to permanently add/usr/local/bin to the system-level path variable, edit the/etc/profile as follows.
$ sudo vi /etc/profile
export PATH=$PATH:/usr/local/bin
After you log in again, the updated environment variable will take effect.
Via:http://ask.xmodulo.com/change-path-environment-variable-linux.html
Dan Nanni Translator: GEEKPI proofreading: Wxy
This article by LCTT original translation, Linux China honors launch
Source: https://linux.cn/article-5478-1.html
Linux Ask a question: How to modify the environment variable path in Linux