linux environment variables can be set up which places the difference


First, the introduction of

Use ubuntu has been more than two years time. When the environment variable is usually set, while in /etc/profilethe 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 ~/.profilein or ~/.pam_environmentset. 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 ~/.profilesettings.
System-level environment variable /etc/profilesettings.

~ / .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

references

Environment Variable seems to be set yet not working

Published 231 original articles · won praise 93 · views 60000 +

Guess you like

Origin blog.csdn.net/wobushixiaobailian/article/details/98341240