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)
2. The current user (permanently valid for the current user)
Modify the current user root directory
.bash_profile or .bashrc
# .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:
3. System environment variables
Modify /etc/profile and add in this file:
..................
export JAVA_HOME=/home/es/java/jdk1.8.0
export PATH=$JAVA_HOME/bin:$PATH
Also to make the configuration file take effect, execute:
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