Persistent environment variables
So far we've only discussed ways set an environment variable value temporarily until the shell session in which it was set is closed. One may wonder if there is a way to somehow permanently set an environment variable to a certain value.
Session-wide environment variables
Suitable files for environment variable settings that should affect just a particular user (rather than the system as a whole) are~/.pam_environment and ~/.profile. After having edited one of those files, you should re-login in order to initialize the variables.
~/.pam_environment
This file is specifically meant for setting a user's environment. It is not a script file, but rather consists of assignment expressions, one per line. This example sets the variable FOO to a literal string and modifies the PATH variable:
FOO=bar PATH DEFAULT=${PATH}:${HOME}/MyPrograms
Note:
You may not quote the value when doing a simple variable assignment like the FOO=bar example.
- The syntax used for modifying PATH, which syntax differs from script files, is required for variable expansion to work.
~/.pam_environment is written to when you use various GUIs to set the language or regional formats. Consequently, if you for instance set LC_TIME by editing ~/.pam_environment manually, your entry will be overwritten if you afterwards use the Language Support GUI to change the regional formats setting.
~/.profile
In this file you can also place environment variable assignments, since it gets executed automatically by the DisplayManager during the start-up process desktop session as well as by the login shell when one logs in from the textual console. This is a ~/.profile equivalent of the above example:
export FOO=bar export PATH="$PATH:$HOME/MyPrograms"
Note: The code in ~/.profile is run after ~/.pam_environment has been read. That makes ~/.profile suitable to use if you want to override a locale related variable that was set in ~/.pam_environment via e.g. Language Support.
Other files
If you are using KDE, see also the KDE User-base page on this topic.
Shell config files such as ~/.bashrc, ~/.bash_profile, and ~/.bash_login are often suggested for setting environment variables. While this may work on Bash shells for programs started from the shell, variables set in those files are not available by default to programs started from the graphical environment in a desktop session.
System-wide environment variables
A suitable file for environment variable settings that affect the system as a whole (rather than just a particular user) is /etc/environment. An alternative is to create a file for the purpose in the /etc/profile.d directory.
/etc/environment
This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line.
FOO=bar
Note: Variable expansion does not work in /etc/environment.
/etc/profile.d/*.sh
Files with the .sh extension in the /etc/profile.d directory get executed whenever a bash login shell is entered (e.g. when logging in from the console or over ssh), as well as by the DisplayManager when the desktop session loads.
You can for instance create the file /etc/profile.d/myenvvars.sh and set variables like this:
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0 export PATH=$PATH:$JAVA_HOME/bin
Other files
While /etc/profile is often suggested for setting environment variables system-wide, it is a configuration file of the base-files package, so it's not appropriate to edit that file directly. Use a file in /etc/profile.d instead as shown above. (Files in /etc/profile.d are sourced by /etc/profile.)
/etc/default/locale is specifically meant for system-wide locale environment variable settings. It's written to by the installer and when you use Language Support to set the language or regional formats system-wide. On a desktop system there is normally no reason to edit this file manually.
The shell config file /etc/bash.bashrc is sometimes suggested for setting environment variables system-wide. While this may work on Bash shells for programs started from the shell, variables set in that file are not available by default to programs started from the graphical environment in a desktop session.
[출처]
https://help.ubuntu.com/community/EnvironmentVariables#Persistent_environment_variables
'컴퓨터공학 리서치 > 공개' 카테고리의 다른 글
dw2pdf 한글 글꼴(CJK font) 설정 (0) | 2016.08.16 |
---|---|
CMakeLists.txt를 사용하여 OpenCV 링크하기 (2) | 2015.10.05 |
우분투(ubuntu)에서 JDK 설치 (0) | 2015.09.03 |
우분투(ubuntu) 바탕화면에 바로가기 만들기 (0) | 2015.09.02 |
안드로이드 adb 및 fastboot 명령 정리 (0) | 2015.03.16 |