Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to modify the environment variable PATH in Linux system

Shulou Source: shulou.com Published: 2022-06-01 16:59:39 09月25日 Update

This article shows you how to modify the environment variable PATH in the Linux system, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

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

$echo $PATH

/ usr/lib64/qt-3.3/bin:/bin:/usr/bin:/usr/sbin:/sbin:/home/xmodulo/bin

Or run:

$env | grep PATH

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, shell will throw an error message: "command not found".

If you want to add another directory (for example: / usr/local/bin) to your PATH variable, you can use the following commands.

Modify the PATH environment variable for a specific user

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

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

Check to see if PATH has been updated:

$echo $PATH

/ usr/lib64/qt-3.3/bin:/bin:/usr/bin:/usr/sbin:/sbin:/home/xmodulo/bin:/usr/local/bin

The updated PATH will remain valid for the current session. However, the changes will expire in the new session.

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

Export PATH=$PATH:/usr/local/bin

Then run the following line of permanent activation changes:

$source ~ / .bashrc (or source ~ / .bash_profile)

Change system-level environment variables

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

$sudo vi / etc/profile

Export PATH=$PATH:/usr/local/bin

When you log back in, the updated environment variables will take effect.

The above is how to modify the environment variable PATH in the Linux system. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Variables environment system commands users directories permanent updated run content skills knowledge face-to-face check login valid concise concise information that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Tech Info Shulou Information MariaDB macOS