Set environment variables in Linux and environment variables in linux
There are two types of Shell sessions: login shell session and non-login shell session. The login shell session prompts the user to enter the user name and password, such as the virtual console session. The terminal session started in the GUI is a typical non-login shell session.
After you log on to the system, the bash program starts and reads a series of startup files. Login shell reads one or more startup files, as shown in the following table:
File |
Description |
/Etc/profile |
Global configuration scripts for all users |
~ /. Bash_profile |
User's personal Startup File. The global configuration script can be expanded or rewritten. |
~ /. Bash_login |
If ~ /. Bash_profile missing, bash tries to read this script |
~ /. Profile |
If ~ /. Bash_profile and ~ /. Bash_login is missing, bash tries to read this file. In Debian-based Linux (such as Ubuntu), this is the default value. |
The Startup File Read by the non-login shell is as follows:
File |
Description |
/Etc/bash. bashrc |
Global configuration scripts for all users |
~ /. Bashrc |
User's personal Startup File. Extensible or program global configuration script |
In addition to reading the above Startup File, the non-login shell inherits the environment of the parent process, which is usually a login shell.
You can customize the environment variables by modifying the Startup File, for example, in ~ /. Bashrc Configuration:
export JAVA_HOME=/usr/lib/jvm/java-7-sunexport PATH=$PATH:${JAVA_HOME}/bin
It is read only when the shell session is started ~ /. Bashrc, SO ~ /. The modification made by bashrc takes effect only when the shell terminal session is closed and restarted. You can also use the source command to re-read bash ~ /. Bashrc file:
source ~/.bashrc