Linux Ask a question: How to modify the environment variable path in Linux

Source: Internet
Author: User

question : When I try to run a program, it prompts "command not found". But this program is under/usr/local/bin. How do I add/usr/local/bin to my path variable so that I can run the command without specifying a path.

In Linux, the PATH environment variable holds a series of directories for the user to search for commands at the time of input. The value of the path variable consists of a series of absolute paths separated by semicolons. Each user has a specific PATH environment variable (initialized by the system-level path variable).

To check the user's environment variables, run the following command in user mode:

    1. $ echo $PATH
    2. /usr/lib64/qt-3.3/bin:/bin:/usr/bin:/usr/sbin:/sbin:/home/xmodulo/bin

or run:

    1. $ env | grep PATH
    2. PATH=/usr/lib64/qt-3.3/bin:/bin:/usr/bin:/usr/sbin:/sbin:/home/xmodulo/bin

If your command does not exist in any of the above directories, the shell throws an error message: "Command not Found".

If you want to add an additional directory (for example:/usr/local/bin) to your PATH variable, you can use these commands.

To modify the PATH environment variable for a specific user

If you only want to temporarily add a new directory (for example:/usr/local/bin) to the user's default search path in the current login session, you only need to enter the following command.

    1. $ PATH=$PATH:/usr/local/bin

Check if path has been updated:

    1. $ echo $PATH
    2. /usr/lib64/ qt-3.3/bin :/bin:/usr/bin:/usr/sbin:/sbin:/ home/xmodulo/bin< Span class= "pun" >:/usr/local/bin

The updated path will remain in effect for the current session. However, the changes will expire in the new session.

If you want to permanently change the path variable, open ~/.BASHRC (or ~/.bash_profile) with the editor and add the following line at the end.

    1. export PATH=$PATH:/usr/local/bin

Then run the following line to permanently activate the changes:

    1. $ source ~/.bashrc (或者 source ~/.bash_profile)
Changing the environment variables at the system level

If you want to permanently add/usr/local/bin to the system-level path variable, edit the/etc/profile as follows.

    1. $ sudo vi /etc/profile

    1. export PATH=$PATH:/usr/local/bin

After you log in again, the updated environment variable will take effect.

Via:http://ask.xmodulo.com/change-path-environment-variable-linux.html

Dan Nanni Translator: GEEKPI proofreading: Wxy

This article by LCTT original translation, Linux China honors launch

Source: https://linux.cn/article-5478-1.html

Linux Ask a question: How to modify the environment variable path 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.