Set user environment variables

 

 

There are several scopes for setting environment variables in linux: 1. The current session; 2. The current user; 3. System environment variables

Take setting the java environment variable as an example:

1. Current session (only valid for current session)

[es@master001 ~]$ export PATH=/usr/java/test:$PATH

 

2. The current user (permanently valid for the current user)

Modify the current user root directory

.bash_profile or .bashrc

[es@master001 ~]$ vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

export JAVA_HOME=/home/es/java/jdk1.8.0
export PATH=$JAVA_HOME/bin:$PATH

 

Then you need to make the configuration file take effect:

[es@master001 ~]$ source .bash_profile

 

3. System environment variables

Modify /etc/profile and add in this file:

[root@master001 ~]# vi /etc/profile
..................
export JAVA_HOME=/home/es/java/jdk1.8.0
export PATH=$JAVA_HOME/bin:$PATH

 Also to make the configuration file take effect, execute:

[es@master001 ~]$ source .bash_profile

 

Note: The environment variable of export PATH takes effect from front to back. The environment variable in the front will overwrite the environment variable in the back. Therefore, when setting the user environment variable, the newly set environment variable is best placed in front of $PATH, for example  export PATH=$JAVA_HOME/bin:$PATH

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326939072&siteId=291194637