Why set an environment variable

Environment variable

Environment variables are used under Linux (as well as under other systems), e.g. to define search paths to program binaries. There are also many other variables in use for all imaginable purposes under Linux.

Where to define these variables depends on the intended purpose. Either you define variables temporarily. The variable definition is therefore only valid until the next restart. If variables are to be set automatically each time the system is started, they can be entered in the corresponding files. However, the syntax is always the same:


The command can be used to output the variable content:

echo $ VARIABLE 0815

The command ensures that the variable is not only available in the current shell, but also in the programs you have called:


You can also put all of this in a single line:

export VARIABLE = 0815

As I said, such variables only apply to the current session. However, variables can also be defined permanently:

  • System-wide change for all users see file.

  • Changes only for one or a few users see file (~ / = home directory of the user).

Environment variables are used when the process is generated inherited, i.e. child processes receive a copy of the environment of the father process and pass this on to their children.

Suppose we also want to have it in the search path - then write in there in a suitable place:

PATH = $ PATH: / usr / local / progdir export PATH

This first defines a variable PATH that contains the value of the previous PATH variable at the beginning, followed by a colon and the one appended at the end. With the export command of the shell this variable is then written into the environment.

Incidentally, .bashrc is also possible, but it is unnecessarily time-consuming because the commands it contains are executed every time a bash is started. Since the environment variables are inherited anyway, this is only necessary once for the login shell; all bash processes started below then inherit the settings.

export http_proxy = http: //my.proxy.company

This also works in the same way with ftp_proxy.

printenv [variable ...]

outputs the value of all or the specified environment variable (s).

The locale environment variables can also be used to set German messages (output and error messages) from programs.

In order to be able to compile KDE programs yourself, various variables have to be set. Here is an example for SuSE 8.X:

export KDEDIR = / opt / kde3 export QTDIR = / usr / lib / qt3

Environment variable (last edited 2010-06-18 08:51:28 by p54A142B6)