UbuntuHelp:EnvironmentVariables
来自Ubuntu中文
点击翻译: |
English |
请不要直接编辑翻译本页,本页将定期与来源同步。 |
- title Environment Variables
目录
Global Environment Variables
These may be put in one of these files:
-
/etc/environment
(try this file first) -
/etc/profile
For example, to set a variable called JAVA_HOME
and append it to PATH
:
for /etc/environment
:
JAVA_HOME="/usr/lib/j2sdk1.5-sun"
(A colon followed by no directory is treated as the current working directory)
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:$JAVA_HOME:"
for /etc/profile
:
export JAVA_HOME="/usr/lib/j2sdk1.5-sun" export PATH="$PATH:$JAVA_HOME:"
Locale Environment variables
Some programs rely on the value of $LANG
, which defaults to en_US.UTF-8
. (For example, Thunderbird changes the displayed date format based on this). The variable is set in both /etc/enviroment
and /etc/default/locale
. To make a system-wide change that is certain to take effect, both of these must be modified; it's also necessary to log out and back in again.
Session Specific Environment Variables
You may sometimes want variables defined locally (eg.: restricted to your accounts shell only) and not globally (all users).
So just append whatever variables you need defined to your ~/.bashrc
file.
If instead you want a temporary variable created only for your current shell session, then do this inside the shell:
export SOMEDIRECTORY="/some/location" export SOMEVALUE="500"
Bash Shell Environment Variables
- When starting a shell after you have logged in already, either from the console or though an X display manager, that shell will be an interactive non-login shell, which will read
/etc/bash.bashrc
and~/.bashrc
. - When the user starts a bash shell by logging into a console or via SSH, this starts a login shell, which will read
/etc/environment
,/etc/profile
,/etc/bash.bashrc
,~/.bash_profile
,~/.bash_login
, and~/.profile
. - If Bash is invoked with the name
sh
, whether as an interactive login shell, or as a non-interactive shell with the--login
option, it first attempts to read and execute commands from/etc/profile
and~/.profile
, in that order.
Displaying contents of $PATH
In a shell type:
echo $PATH