1. What is an environment variable (PATH)
In Linux, when the command is executed, the system will follow the path's settings to search for execution files under the paths defined by each path, and the first files to be searched are executed first.
We know the instructions for checking the properties of a file ls full file name:/bin/ls (This is the absolute path), then you will not find it strange: "Why can I execute the/bin/ls command anywhere?" "Why do I enter LS in any directory to show some information without saying that I can't find the/bin/ls directive?" This is due to the help of the environment variable PATH!
When we execute a command, for example, "LS" is good, the system will follow the path of the directory defined by each path to search for the executable file named LS, if the directory defined in path contains more than one executable file named LS, then the first to search for the same name command is executed first!
2. How to change path
A. Directly modify the $path value:
echo $PATH//View the configuration path of the current path
Export path= $PATH:/xxx/xxx//Add the required configuration path to the $path equals must not have spaces on both sides
Once configured, you can view the results of the configuration with the first sentence command.
Effective method: Immediate effect
Validity period: Temporary change, only in the current terminal window, the current window will be restored after the original path configuration
User limitations: Only for the current user
B. By modifying the. bashrc file: (. bashrc file in the root directory)
Vi. BASHRC//edit. bashrc file
Add on the last line:
Export path= $PATH:/xxx/xxx///xxx/xxx bits need to add environment variable address equals no spaces on both sides
Effective method: (There are the following two kinds)
.. Close the current terminal window and reopen a new terminal window to take effect
.. Enter "source. BASHRC" command, effective immediately
Expiry date: Permanently valid
User limitations: Only for the current user
C. By modifying the profile file: (profile file in/etc directory)
Vi/etc/profile//Edit Profile
Add on the last line:
Export path= $PATH:/xxx/xxx
Effective method: System restart
Expiry date: Permanently valid
User limitations: For all users
D. By modifying the Environment file: (Environment file in/etc directory)
Vi/etc/profile//Edit Profile
In path=/ Add ":/xxx/xxx"
Effective method: System restart
Expiry date: Permanently valid
User limitations: For all users
Modify environment variable path under Linux