Environment variables

From ArchWiki
Revision as of 00:37, 31 May 2011 by Jeff story (talk | contribs) (Defining Variables Globally)
Jump to: navigation, search

The source for most of this info is from: Gentoo Linux Documentation [1]

Please contribute by adding, changing, editing, correcting or whatever else it needs to more accurately reflect an Arch Linux system.

Environment Variables

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.

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 command, such as /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.

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.

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

EDITOR This variable contains the path to the program used to change the contents of files with (such as nano or vi).

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

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









To list the environment variables that are currently set on your machine, use the following command:

$ env | LC_ALL=C sort

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 contain local environment variables on your Arch system: ~/.bash_profile, ~/.bashrc, ~/.profile, ~/.bash_logout

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. If you want to define an environment variable locally, you should use ~/.bashrc or ~/.bash_profile:

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


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"