Get the App
SLTechnology News&Howtos  ›  Development  › 

How to modify environment variables in Linux system

Shulou Source: shulou.com Published: 2022-06-01 21:21:22 10月21日 Update

This article shows you how to modify environment variables in 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.

1. Add a variable to the / etc/profile file [effective for all users (permanent)]

Add a variable to the file / etc/profile file with VI, which will be valid for all users under Linux and will be "permanent".

For example: edit / etc/profile file, add CLASSPATH variable

\ # vi / etc/profile export CLASSPATH=./JAVA_HOME/lib;$JAVA_HOME/jre/lib Note: if you want to take effect immediately after modifying the file, you have to run # source / etc/profile, otherwise it will only take effect the next time you reenter this user.

2. Add a variable to the. bash_profile file under the user directory [effective for a single user (permanent)]

Use VI to add variables to the. bash_profile file in the user directory, and the changes are only valid for the current user and are "permanent".

For example: edit the. bash_profile under the guok user directory (/ home/guok)

$vi / home/guok/.bash.profile adds the following:

Export CLASSPATH=./JAVA_HOME/lib;$JAVA_HOME/jre/lib note: if you want to change the file to take effect immediately, you have to run $source / home/guok/.bash_profile, otherwise it will only take effect the next time you reenter this user.

3. Run the export command directly to define variables [valid only for the current shell (BASH) (temporary)]

Use [export variable name = variable value] directly under the command line of shell

Define a variable, which is valid only under the current shell (BASH) or its child shell (BASH). When shell is closed, the variable is invalid, and there is no such variable when you open the new shell. You need to redefine it if you need to use it.

The above is how the Linux system modifies the environment variables. 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 users files valid permanent content directories runs environments systems commands skills knowledge immediately concise to the point that is articles more articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Technology NVidia Docker Linux