How to modify the PATH of the system environment variable in Linux

Source: Internet
Author: User

How to modify the PATH of the system environment variable in Linux: PATH is a string variable. When a command is input, LINUX searches for the PATH recorded in the PATH. For example, you can enter the ls command in the root directory/or 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. About the new custom path: Now suppose you have installed a new command under/usr/locar/new/bin, and you want to use this command anywhere like ls, you need to modify the environment variable PATH. To be precise, add a value/usr/locar/new/bin to the PATH. You only need a line of bash command export PATH = $ PATH:/usr/locar/new/bin. The meaning of this command is too clear, so that PATH auto-increment:/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 directly use source/root/. bashrc to execute this file and log on again. You can use the echo $ PATH command to view the value of PATH. About deleting a custom path: when one day you find that your new path/usr/locar/new/bin is useless, you can modify/root /. the path you added in the bashrc file. Or you can modify the/etc/profile file to delete the path that you do not need. However, Linux is developing very rapidly and is catching up with Microsoft. Here we will introduce the knowledge of Linux, so that you can learn how to use Linux. For example, to add the/etc/apache/bin directory to the PATH, there are 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. 2. # vi/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, the value of PATH will not be changed unless you manually modify it. # vi ~ /. Modify the PATH row in bash_profile and add/etc/apache/bin to it. Note: to change the PATH, you must log on again to make it take effect. The following methods can be simplified: if/etc/profile is modified, run the source profile or dot command after editing. /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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.