Article Directory
First, the introduction of
Use ubuntu has been more than two years time. When the environment variable is usually set, while in /etc/profile
the configuration, while in~/.bashrc
设置。网上又有说在其它地方设置的。具体下来,有这么些地方。
- /etc/profile
- /etc/environment
- ~/.bashrc
- ~/.profile
- ~/.
Second, the environment variable to place and differences
2.1 session-level environment variables
Session level environment variables (Session-wide environment variables), affects only a particular user, and does not affect all users. Usually ~/.profile
in or ~/.pam_environment
set. After setting, you need to re-login system to take effect.
- ~ / .Pam_environment. Not a script file. Environment variable settings in the file example.
FOO=bar
PATH DEFAULT=${PATH}:/home/@{PAM_USER}/MyPrograms
- ~ / .Profile. It is a script file. After reading system reads ~ / .pam_environment ~ / .profile, environment variable can be rewritten, covering its value. Environment variable settings in the file example.
export FOO=bar
export PATH="$PATH:$HOME/MyPrograms"
You can also set session-level environment variables elsewhere. The above two settings are compatible with different ways of linux systems. Different systems set the environment variable areas may be somewhat different. As the ubuntu ~ / .bashrc, ~ / .bash_profile, and ~ / .bash_login, environment variable settings in these files in the bash shell is appropriate, however, to open the graphical program does not support.
2.2 system-level environment variables
System-level environment variables that affect the entire system, rather than a specific user.
- / Etc / environment. This file is not a script file, not run. In this configuration file inside yes.
FOO=bar
- /etc/profile.d directory. .sh file in this directory named after your goals. But when, upon landing bash shell (ssh or console) will be executed. The arrangement way is to create /etc/profile.d/xx.sh, and set it inside.
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0
export PATH=$PATH:$JAVA_HOME/bin
Other settings System environment variables where there is / etc / profile.
Third, the summary
Session level environment variable ~/.profile
settings.
System-level environment variable /etc/profile
settings.
~ / .bashrc each time you open the terminal will be re-set environment variables is not necessary. And ./bashrc only affects the command line open programs.
~ / .bash_profile. If ~ / .bash_profile exists, then this file is read, instead of ~ / .profile file.
~ / .profile. It can be recognized a lot of shell scripts.
ubuntu documentation, description of environment variables EnvironmentVariables