Change PATH in Ubuntu Linux

Source: Internet
Author: User

Change PATH in Ubuntu Linux

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

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.