An environment variable is a mapping of a name to a value which is visible to processes on Unix (including Mac OS X) and Windows operating systems. Environment variables exist so that a program's behavior can be altered by setting their values. A program may check for zero, one, or many environment variable values when it runs. The names of the environment variables a program will look for are generally hard-coded into the program; the values are defined by the user. Some programs may simply check for the existence of an environment variable (whether it has been "set") and ignore its contents (which may be empty or set to some text, numeric, or other value).
An environment variable may be set temporarily for a single shell (or command prompt) or persistently (so that it affects all future shells or command prompts). There are not actually two kinds of environment variables, just two ways of setting them. This article details the steps for setting persistent environment variables. On Unix, these variables and their values are stored in shell initialization scripts in the user's home directory. On Windows, these variables and their values are stored in the registry (but are modified through the Windows Explorer shell).
To set the environment variable for your Windows user:
All new command prompt windows will start programs with the newly configured environment variable. If you decide you do not want a program's behavior to be affected by an environment variable, repeat the steps above to get to the Environment Variables window but click Delete instead of New. All future command prompt windows will be affected.
Open the file ~/.profile in a text editor. At the end of a file, create two lines containing text like the following (substituting the desired name and value):
NAME="value"
export NAME
Save and close the file.
All new sh shells for your Unix user will now have the environment variable name set to value value. If you decide you do not want a program's behavior to be affected by the environment variable, simply remove the two lines from ~/.profile. After logging out and logging back in, programs run from your sh shell will no longer have the name environment variable set.
Open the file ~/.bashrc (bash), ~/.zshrc (zsh), or ~/.profile (ksh) in a text editor. At the end of a file, create a line containing text like the following (substituting the desired name and value):
export NAME="value"
Save and close the file.
All new shells for your Unix user will now have the environment variable name set to value value. If you decide you do not want a program's behavior to be affected by the environment variable, simply remove the line from the initialization file you edited. After logging out and logging back in, programs run from your shell will no longer have the name environment variable set.
Open the file ~/.cshrc (~/.tcshrc for tcsh) in a text editor. At the end of a file, create a line containing text like the following (substituting the desired name and value):
setenv NAME "value"
Save and close the file.
All new csh/tcsh shells for your Unix user will now have the environment variable name set to value value. If you decide you do not want a program's behavior to be affected by the environment variable, simply remove the line from the initialization file you edited. After logging out and logging back in, programs run from your csh/tcsh shell will no longer have the name environment variable set.