1. What is the environment variable (PATH) in Linux? When executing a command, the system searches for the execution file under the PATH defined by each PATH according to the PATH settings, the file to be searched is executed first. We know that the complete file name of the command ls for viewing file properties is/bin/ls (this is an absolute path). Do you think this is strange: "Why can I execute the/bin/ls command anywhere? "Why do I enter ls in any directory to display some messages without saying that the/bi cannot be found?
1. What is environment variable (PATH)
In Linux, when executing a command, the system searches for the execution file in the PATH defined by each PATH according to the PATH settings. The first searched file is executed first.
We know that the complete file name of the command ls for viewing file properties is/bin/ls (this is an absolute path). Do you think this is strange: "Why can I execute the/bin/ls command anywhere? "Why do I enter ls in any directory to display some messages without saying that the/bin/ls command cannot be found? This is because of the help of the Environment Variable PATH!
When we execute an explain command, for example, "ls", the system will search for executable files whose names are ls in the directory defined by each PATH according to the PATH settings, if the directory defined by PATH contains multiple executable files named ls, the command with the same name of "Workers" is first searched and executed!
2. How to change the PATH
A. directly modify the value of $ PATH:
Echo $ PATH // view the configuration PATH of the current PATH
Export PATH = $ PATH:/xxx // Add the required PATH to the $ PATH equal sign. There must be no space on both sides.
// After configuration, you can view the configuration result using the first command.
Effective Method: Effective immediately
Validity Period: Temporary change. It can only be valid in the current terminal window. After the current window is closed, the original path configuration will be restored.
User restrictions: only for the current user
B. Modify the. bashrc file: (The. bashrc file is in the root directory)
Vi. bashrc // edit the. bashrc File
// Add the following to the last line:
Export PATH = $ PATH:/xxx // xxx/xxx the environment variable address to be added with no space on both sides of the equal sign
Effective Method: (two methods are available)
.. Close the current terminal window and open a new terminal window to take effect.
.. Enter the "source. bashrc" command to take effect immediately
Validity Period: permanently valid
User restrictions: only for the current user
C. Modify the profile file: (the profile file is under the/etc directory)
Vi/etc/profile // edit the profile file
// Add the following to the last line:
Export PATH = $ PATH:/xxx
Effective Method: system restart
Validity Period: permanently valid
User restrictions: for all users
D. Modify the environment File: (the environment file is in the/etc directory)
Vi/etc/profile // edit the profile file
Add ":/xxx" to PATH ="
Effective Method: system restart
Validity Period: permanently valid
User restrictions: for all users
For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2
This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-05/116993.htm