Linux PATH environment variable parsing about the role of PATH: www.2cto.com PATH is simply a string variable. when you enter a command, LINUX will find the PATH recorded in the PATH. For example, you can enter the ls command in the root directory,
You can also enter ls in the/usr directory, but the ls command is not in the two directories at all. In fact, when you enter a command, LINUX will go to/bin,/usr/bin,/sbin and other directories to find the command you entered at this time, and the value of PATH is exactly/bin: /sbin:/usr/bin :....... The colon separates directories from directories. For example, if a new command is installed under/usr/locar/new/bin, if you want to use this command anywhere like ls, you need to modify the environment variable PATH. To be accurate, add a value/usr/locar/new/bin to the PATH. A line of bash command: export PATH = $ PATH:/usr/locar/new/bin is required. This command indicates auto-increment of PATH:/usr/locar/new/bin, PATH = PATH + ":/usr/locar/new/bin"; the common practice is to write this line of bash command to/root /. at the end of bashrc, When you log on to LINUX again (this file should be executed when linux is started), the new default path will be added. Of course, you can also run the command source/root/. bashrc to re-log on to the file. You can run the echo $ PATH command to view the value of PATH. Delete a custom path from www.2cto.com: if the new path/usr/locar/new/bin is useless, you can modify the path you added in the/root/. bashrc file. You can also modify the/etc/profile file to delete unnecessary path modifications/root/. bashrc files, delete the corresponding environment variable options, and then ¥ source/root/. bashrc. Or you can use the command. To delete the/usr/local/del/bin: variable in the PATH, enter $ export PATH =$ (echo $ PATH | sed's /: \/usr \/local \/del \/bin: //:/G') Note: "/" indicates the conversion character. For example, you need to add the/etc/apache/bin directory to the PATH by using three methods: 1. $ PATH = $ PATH:/etc/apache/bin this method is only valid for the current session. That is to say, the PATH setting will expire after the system is logged out or logged out. $ vim/etc/profile add PATH = $ PATH:/etc/apache/bin in the appropriate position (Note: = there cannot be any space on both sides of the equal sign) This method is best, unless you manually modify the PATH value, it will not be changed to www.2cto.com 3. $ vim ~ /. Modify the PATH row in bash_profile and add/etc/apache/bin to the directory. NOTE: to change the PATH, you must log on again to make it take effect. The following methods can be simplified: if the/etc/profile is modified, run $ source profile (source/etc/profile) or the command $. /profile, the value of PATH will take effect immediately. The principle of this method is to execute the/etc/profile shell script again. Note that if sh/etc/profile is used, sh is executed in the sub-shell process, even if the PATH is changed, it will not be reflected in the current environment, but the source is executed in the current shell process, so we can see the PATH change. In this way, you will learn how to modify the PATH of the environment variable in Linux. Www.2cto.com added that there are two types of file environment setting files in the work environment: system environment setting files and personal environment setting files 1. user working environment setting file in the system: logon environment setting file:/etc/profile non-Logon environment setting file:/etc/bashrc 2. environment setting file set by the user: logon environment setting file: $ HOME /. bash_profile // This is the environment variable setting place. Non-Logon environment setting file: $ HOME /. bashrc // This is the local logon environment that defines the alias. It refers to the non-Logon environment in which the user logs on to the system. It refers to the user environment used when the user calls the sub-shell.