特殊:Badtitle/NS100:EnvironmentVariables
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/EnvironmentVariables }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/af | • {{#if: UbuntuHelp:EnvironmentVariables|Afrikaans| [[::EnvironmentVariables/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/ar | • {{#if: UbuntuHelp:EnvironmentVariables|العربية| [[::EnvironmentVariables/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/az | • {{#if: UbuntuHelp:EnvironmentVariables|azərbaycanca| [[::EnvironmentVariables/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/bcc | • {{#if: UbuntuHelp:EnvironmentVariables|جهلسری بلوچی| [[::EnvironmentVariables/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/bg | • {{#if: UbuntuHelp:EnvironmentVariables|български| [[::EnvironmentVariables/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/br | • {{#if: UbuntuHelp:EnvironmentVariables|brezhoneg| [[::EnvironmentVariables/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/ca | • {{#if: UbuntuHelp:EnvironmentVariables|català| [[::EnvironmentVariables/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/cs | • {{#if: UbuntuHelp:EnvironmentVariables|čeština| [[::EnvironmentVariables/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/de | • {{#if: UbuntuHelp:EnvironmentVariables|Deutsch| [[::EnvironmentVariables/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/el | • {{#if: UbuntuHelp:EnvironmentVariables|Ελληνικά| [[::EnvironmentVariables/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/es | • {{#if: UbuntuHelp:EnvironmentVariables|español| [[::EnvironmentVariables/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/fa | • {{#if: UbuntuHelp:EnvironmentVariables|فارسی| [[::EnvironmentVariables/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/fi | • {{#if: UbuntuHelp:EnvironmentVariables|suomi| [[::EnvironmentVariables/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/fr | • {{#if: UbuntuHelp:EnvironmentVariables|français| [[::EnvironmentVariables/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/gu | • {{#if: UbuntuHelp:EnvironmentVariables|ગુજરાતી| [[::EnvironmentVariables/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/he | • {{#if: UbuntuHelp:EnvironmentVariables|עברית| [[::EnvironmentVariables/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/hu | • {{#if: UbuntuHelp:EnvironmentVariables|magyar| [[::EnvironmentVariables/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/id | • {{#if: UbuntuHelp:EnvironmentVariables|Bahasa Indonesia| [[::EnvironmentVariables/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/it | • {{#if: UbuntuHelp:EnvironmentVariables|italiano| [[::EnvironmentVariables/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/ja | • {{#if: UbuntuHelp:EnvironmentVariables|日本語| [[::EnvironmentVariables/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/ko | • {{#if: UbuntuHelp:EnvironmentVariables|한국어| [[::EnvironmentVariables/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/ksh | • {{#if: UbuntuHelp:EnvironmentVariables|Ripoarisch| [[::EnvironmentVariables/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/mr | • {{#if: UbuntuHelp:EnvironmentVariables|मराठी| [[::EnvironmentVariables/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/ms | • {{#if: UbuntuHelp:EnvironmentVariables|Bahasa Melayu| [[::EnvironmentVariables/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/nl | • {{#if: UbuntuHelp:EnvironmentVariables|Nederlands| [[::EnvironmentVariables/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/no | • {{#if: UbuntuHelp:EnvironmentVariables|norsk| [[::EnvironmentVariables/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/oc | • {{#if: UbuntuHelp:EnvironmentVariables|occitan| [[::EnvironmentVariables/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/pl | • {{#if: UbuntuHelp:EnvironmentVariables|polski| [[::EnvironmentVariables/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/pt | • {{#if: UbuntuHelp:EnvironmentVariables|português| [[::EnvironmentVariables/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/ro | • {{#if: UbuntuHelp:EnvironmentVariables|română| [[::EnvironmentVariables/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/ru | • {{#if: UbuntuHelp:EnvironmentVariables|русский| [[::EnvironmentVariables/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/si | • {{#if: UbuntuHelp:EnvironmentVariables|සිංහල| [[::EnvironmentVariables/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/sq | • {{#if: UbuntuHelp:EnvironmentVariables|shqip| [[::EnvironmentVariables/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/sr | • {{#if: UbuntuHelp:EnvironmentVariables|српски / srpski| [[::EnvironmentVariables/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/sv | • {{#if: UbuntuHelp:EnvironmentVariables|svenska| [[::EnvironmentVariables/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/th | • {{#if: UbuntuHelp:EnvironmentVariables|ไทย| [[::EnvironmentVariables/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/tr | • {{#if: UbuntuHelp:EnvironmentVariables|Türkçe| [[::EnvironmentVariables/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/vi | • {{#if: UbuntuHelp:EnvironmentVariables|Tiếng Việt| [[::EnvironmentVariables/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/yue | • {{#if: UbuntuHelp:EnvironmentVariables|粵語| [[::EnvironmentVariables/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/zh | • {{#if: UbuntuHelp:EnvironmentVariables|中文| [[::EnvironmentVariables/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/zh-hans | • {{#if: UbuntuHelp:EnvironmentVariables|中文(简体)| [[::EnvironmentVariables/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EnvironmentVariables | UbuntuHelp:EnvironmentVariables | {{#if: | :}}EnvironmentVariables}}/zh-hant | • {{#if: UbuntuHelp:EnvironmentVariables|中文(繁體)| [[::EnvironmentVariables/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:EnvironmentVariables|:EnvironmentVariables|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :EnvironmentVariables/zh | | {{#ifexist: EnvironmentVariables/zh | | {{#ifeq: {{#titleparts:EnvironmentVariables|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:EnvironmentVariables|1|-1|}} | zh | | }}
- 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