个人工具

“UbuntuHelp:EnvironmentVariables”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第18行: 第18行:
 
<pre><nowiki>
 
<pre><nowiki>
 
export JAVA_HOME="/usr/lib/j2sdk1.5-sun"
 
export JAVA_HOME="/usr/lib/j2sdk1.5-sun"
 +
 
export PATH="$PATH:$JAVA_HOME:"
 
export PATH="$PATH:$JAVA_HOME:"
 
</nowiki></pre>
 
</nowiki></pre>

2007年12月6日 (四) 10:30的版本

  1. 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

References