Difference between revisions of "Environment variables"

From ArchWiki
Jump to: navigation, search
(add section describing the essential utilities)
(Examples: added Codeline and Package Official formatting; added a Note box regarding the MANPATH var; added wiki link to KDE)
Line 23: Line 23:
  
 
----
 
----
'''PATH''' This variable contains a colon-separated list of directories in which your system looks for executable files. If you enter a name of an executable (such as ls, rc-update or emerge) but this executable is not located in a listed directory, your system will not execute it (unless you enter the full path as command, such as /bin/ls).
+
'''PATH''' This variable contains a colon-separated list of directories in which your system looks for executable files. If you enter a name of an executable (such as ls, rc-update or emerge) but this executable is not located in a listed directory, your system will not execute it (unless you enter the full path as a command, such as {{Codeline|/bin/ls}}).
  
 
'''ROOTPATH'''  This variable has the same function as PATH, but this one only lists the directories that should be checked when the root-user enters a command.
 
'''ROOTPATH'''  This variable has the same function as PATH, but this one only lists the directories that should be checked when the root-user enters a command.
Line 30: Line 30:
  
 
'''MANPATH''' This variable contains a colon-separated list of directories in which the man command searches for the man pages.
 
'''MANPATH''' This variable contains a colon-separated list of directories in which the man command searches for the man pages.
 +
 +
{{Note|In {{Filename|/etc/profile}}, there is a comment that states "Man is much better than us at figuring this out" when referring to the '''MANPATH''' environment variable.}}
  
 
'''INFODIR''' This variable contains a colon-separated list of directories in which the info command searches for the info pages.
 
'''INFODIR''' This variable contains a colon-separated list of directories in which the info command searches for the info pages.
  
'''PAGER''' This variable contains the path to the program used to list the contents of files through (such as less or more).
+
'''PAGER''' This variable contains the path to the program used to list the contents of files through (such as {{Package Official|less}} or more).
  
'''EDITOR''' This variable contains the path to the program used to change the contents of files with (such as nano or vi).
+
'''EDITOR''' This variable contains the path to the program used to change the contents of files with (such as {{Package Official|nano}}, {{Package Official|vi}}, or {{Package Official|vim}}).
  
'''KDEDIRS''' This variable contains a colon-separated list of directories which contain KDE-specific material.
+
'''KDEDIRS''' This variable contains a colon-separated list of directories which contain [[KDE]]-specific material.
 
----
 
----
  

Revision as of 18:16, 3 October 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

An environment variable is a named object that contains information used by one or more applications. Many users (and especially those new to Linux) find this a bit weird or unmanageable. However, this is a mistake: by using environment variables one can easily change a configuration setting for one or more applications.

Utilities

The Template:Package Official package contains Template:Codeline and Template:Codeline.

Use Template:Codeline to print the names and values of current environment variables:

$ printenv
Note: Some environment variables are user-specific. Check by comparing the Template:Codeline output as root.

The Template:Codeline utility can be used to run a command under a modified environment. In the simplest case:

$ env [NAME=VALUE] [COMMAND]

The Bash builtin Template:Codeline "allows you to change the values of shell options and set the positional parameters, or to display the names and values of shell variables"[1]:

Examples

The following table lists a number of variables used by a Linux system and describes their use.


PATH This variable contains a colon-separated list of directories in which your system looks for executable files. If you enter a name of an executable (such as ls, rc-update or emerge) but this executable is not located in a listed directory, your system will not execute it (unless you enter the full path as a command, such as Template:Codeline).

ROOTPATH This variable has the same function as PATH, but this one only lists the directories that should be checked when the root-user enters a command.

LDPATH This variable contains a colon-separated list of directories in which the dynamical linker searches through to find a library.

MANPATH This variable contains a colon-separated list of directories in which the man command searches for the man pages.

Note: In Template:Filename, there is a comment that states "Man is much better than us at figuring this out" when referring to the MANPATH environment variable.

INFODIR This variable contains a colon-separated list of directories in which the info command searches for the info pages.

PAGER This variable contains the path to the program used to list the contents of files through (such as Template:Package Official or more).

EDITOR This variable contains the path to the program used to change the contents of files with (such as Template:Package Official, Template:Package Official, or Template:Package Official).

KDEDIRS This variable contains a colon-separated list of directories which contain KDE-specific material.



The values for the above variables are defined in following table.


PATH="/bin:/usr/bin:/usr/local/bin:/opt/bin:/usr/games/bin"

ROOTPATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"

LDPATH="/lib:/usr/lib:/usr/local/lib:/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3"

MANPATH="/usr/share/man:/usr/local/share/man"

INFODIR="/usr/share/info:/usr/local/share/info"

PAGER="/usr/bin/less"

EDITOR="/usr/bin/vim"

KDEDIRS="/usr"


Defining Variables Globally

Most Linux distributions tell you to change or add environment variable definitions in /etc/profile or other locations. Be sure to maintain and manage the environment variables and pay attention to the numerous files that can contain environment variables. The following files may be present and used for global environment variables on your Arch system: /etc/profile, /etc/bash.bashrc, /etc/environment

Defining Variables Locally

User Specific

You do not always want to define an environment variable globally. For instance, you might want to add /home/my_user/bin and the current working directory (the directory you are in) to the PATH variable but don't want all other users on your system to have that in their PATH too. The following files may be present and used for local environment variables on your Arch system: ~/.bashrc, ~/.bash_profile, ~/.profile, ~/.bash_login, ~/.bash_logout

Example: Extending PATH for local usage in ~/.bashrc (A colon followed by no directory is treated as the current working directory)

PATH="${PATH}:/home/my_user/bin:"

When you relogin, your PATH variable will be updated.

Session Specific Variables

Sometimes even stricter definitions are requested. You might want to be able to use binaries from a temporary directory you created without using the path to the binaries themselves or editing ~/.bashrc for the short time you need it.

In this case, you can just define the PATH variable in your current session by using the export command. As long as you don't log out, the PATH variable will be using the temporary settings.

Example: Defining a session-specific environment variable

# export PATH="${PATH}:/home/my_user/tmp/usr/bin"

A Users Example

To set the global environment variables for BROWSER and EDITOR, I tried several files and was finally successful putting the following in the /etc/environment file.

BROWSER=firefox

EDITOR=nano

Be sure to re-login and check in a terminal to see if they are now set.

additional info: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html

References

Gentoo Linux Documentation [2]