====== Environmental variables ======
Environmental variables are used to configure - guess what - your computer environment. They store information that is used by both the operating system and individual programs. Typically, environmental variables are written in all uppercase letters and are preceded by a $ sign. One prominent example is the variable
$PATH
===== $PATH =====
The environmental variable //$PATH// stores all paths where the operating system automatically looks for executable programs and scripts. If the path to a program you want to use is stored in $PATH, you can call this program from anywhere in the directory tree just by typing its name. For example when you type
ls
The computer will execute the function ''ls'' that is located at ''/usr/bin/ls''
For all other programs, the path to the executable file hast to be specified in the program call.
===== What is the value of my environmental variable? =====
You can check for the value of an environmental variable by simply calling the function //echo// followed by the variable name
echo $PATH
===== Modifying environmental variables =====
==== only in the active shell ====
If a program that is not in your default //PATH// is used many times, it might be convenient to add its location to //$PATH// by using the //export// command. For example,
export PATH=$PATH:/home/andreas/bin
adds the directory /home/andreas/bin to the paths stored in $PATH. Please note, that to the right of the equation sign we write both $PATH and the new path separated by a colon. If you omit the $PATH, you will overwrite the contents in $PATH.
==== permanently ====
Changing //$PATH// via the //export// function is valid only for the current terminal and for the ongoing session. The information will be lost once you change to another terminal, or when you close and restart the terminal. For a permanent modification of $PATH you will need to modify the configuration file that is located in your home directory and is typically named
.bashrc
Once you have modified the ''.bashrc'', you will have to do either of the two following actions
- close and reopen your shell
- force the operating system to re-read the contents of the ''.bashrc'' by typing
source ~/.bashrc
* [[general:computerenvironment|Back to Computer Environment]]