Variables d'environnement

Updated 4 Juillet 2019

Variables d'environnement

What are environment variables?

An environment variable is a named object that contains information used by one or more applications. Some users, especially newcomers to Linux, tend to find this behaviour somewhat strange or unmanageable. But this is wrong as, in fact, you can easily tune software configurations with environment variables.

Exemples importants

The following table describes a number of variables used on Linux systems. Some examples are given below.

Variable Description
PATH This variable stores a list of colon-separated directories for the system to look for executable files. If you enter an executable name such as ls, rc-update or emerge, which is not in any of the directories listed here, it will not run (unless, of course, you have specified the full path, such as /bin/ls).
ROOTPATH This variable has the same function as PATH, but it lists only the directories you want to see when entering a command as root.
LDPATH This variable stores a list of colon-separated directories for the dynamic linker to look for libraries.
MANPATH This variable stores a list of colon-separated directories for the man command to look for man pages.
INFODIR This variable stores a list of colon-separated directories for the info command to look for info pages.
PAGER This variable stores the path to the utility that allows you to view the contents of files page by page, such as less or more.
EDITOR This variable stores the path to the file editor program, i.e. vi or nano.
KDEDIRS This variable stores a list of colon-separated directories containing KDE resources.
CLASSPATH This variable stores a list of colon-separated directories containing Java classes.
CONFIG_PROTECT This variable stores a list of space separated directories, protected by Portage from update.
CONFIG_PROTECT_MASK This variable stores a list of space-separated directories that are excluded from Portage protection at update time.

See below how all these variables can be defined:

CONFIG_PROTECT="/usr/X11R6/lib/X11/xkb /opt/tomcat/conf \
                /usr/kde/3.1/share/config /usr/share/texmf/tex/generic/config/ \
                /usr/share/texmf/tex/platex/config/ /usr/share/config"

Globally defined variables


To define them in a more centralized way, Calculate uses the /etc/env.d directory. It contains a number of files, for example, "00basic", "05gcc" and so on, that define variables required by the package specified in the file name.

For instance, when you install gcc, its ebuild creates a file named /etc/env.d/05gcc that contains the following variable definitions:


In other distributions, you are asked to modify or add definitions of environment variables in /etc/profile or elsewhere. On the other hand, Calculate makes it easy for you to support and manage your environment variables, freeing you from having to handle multiple files with variable definitions.

For instance, when gcc is updated, /etc/env.d/05gcc is also updated automatically.

This not only benefits Portage, but also the user. You may need to set a variable globally. Let's take http_proxy as an example. Instead of messing with /etc/profile, you can now simply create a ~~99local~ file and put all the necessary definitions to it:



With the same file for all of your variables, you can easily see all of your variables together.


PATH is defined in multiple files in /etc/env.d. This is not an error: when you run env-update, definitions are merged before updating the environment variables, allowing packages (or users) to add their own values without interfering with existing ones.

The env-update script merges the values of the variables stored in the files located in /etc/env.d, in alphabetical order. The file names must begin with two decimal digits. This is how env-update operates:

          00basic        99kde-env       99local

Merging is performed for the following variables only: KDEDIRS, PATH, CLASSPATH, LDPATH, MANPATH, INFODIR, INFOPATH, ROOTPATH, CONFIG_PROTECT, CONFIG_PROTECT_MASK, PRELINK_PATH and PRELINK_PATH_MASK. For all the other variables, the value defined in the last file (among those stored in the alphabetical order in /etc/env.d) is used.

When you run the env-update script, all environment variables are created and put in /etc/profile.env (used by /etc/profile). Besides, the LDPATH+ value is used to create /etc/ After that, ldconfig is run to update the /etc/ file used by the dynamic linker.

If you want the results of env-update operation to take effect immediately, run the following command to update the environment:

env-update && source /etc/profile

Note: This command updates variables only in the current terminal, new terminal instances and their descendants. It means that if you are working in an X11 environment, you will need to either type source /etc/profile in each new terminal, or restart X so that all new terminals address new variables. If you are using the Login Manager, log in as root and type /etc/init.d/xdm restart. If not, you will have to log out and log in again for X to generate descendants using the updated values.

Locally defined variables

User variables

All variables do not have to be defined globally. For example, a user may need to add ~/home/my_user/bin~~ and the current working directory (where they are now) to the PATH variable, but to their PATH variable only. To define an environment variable locally, edit ~/.bashrc or ~/.bash_profile. Example of PATH extension for local needs:


#(A colon without further directory entry means the current working directory)

Your PATH variable will be updated when you log out and then in again.

Session variables

Sometimes, even stronger restrictions are needed. You may need to be able to run executables in a dedicated temporary directory without specifying the full path to them and without having to edit ~/.bashrc.

In this case, you can simply define PATH for the current session with the export command. The variable will be assigned a temporary value until you exit the session. Example of defining an environment variable for a session:

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