The environment is a feature of the operating system; it consists of a collection of variables with names and values. Each variable is called an environment variable; environment variable names are case-sensitive, and it is conventional to use upper case letters only. The values are all text strings.
What makes the environment useful is that subprocesses inherit the environment automatically from their parent process. This means you can set up an environment variable in your login shell, and all the programs you run (including Emacs) will automatically see it. Subprocesses of Emacs (such as shells, compilers, and version-control software) inherit the environment from Emacs, too.
Inside Emacs, the command M-x getenv gets the value of an environment variable. M-x setenv sets a variable in the Emacs environment. The way to set environment variables outside of Emacs depends on the operating system, and especially the shell that you are using. For example, here's how to set the environment variable ORGANIZATION to not very much using Bash:
export ORGANIZATION="not very much"
and here's how to do it in csh or tcsh:
setenv ORGANIZATION "not very much"
When Emacs is set-up to use the X Window System, it inherits the use of a large number of environment variables from the X libraries. See the X documentation for more information.
Here is an alphabetical list of specific environment variables that have special meanings in Emacs, giving the name of each variable and its meaning. Most of these variables are also used by some other programs. Emacs does not require any of these environment variables to be set, but it uses their values if they are set.
Used by the cd command to search for the directory you specify, when you specify a relative directory name.
The name of the Internet domain that the machine running Emacs is located in. Used by the Gnus package.
Defining this environment variable with a nonempty value directs Emacs to do almost everything with single-byte buffers and strings. It is equivalent to using the -unibyte command-line option on each invocation. Section B.2.
Directory for the architecture-independent files that come with Emacs. This is used to initialize the Lisp variable data-directory.
Directory for the documentation string file, DOC-emacsversion. This is used to initialize the Lisp variable doc-directory.
A colon-separated list of directories to search for Emacs Lisp files--used to initialize load-path.
A colon-separated list of directories to search for executable files--used to initialize exec-path.
Used for shell-mode to override the SHELL environment variable.
The name of the file that shell commands are saved in between logins. This variable defaults to ~/.bash_history if you use Bash, to ~/.sh_history if you use ksh, and to ~/.history otherwise.
The location of the user's files in the directory tree; used for expansion of file names starting with a tilde (~). On MS-DOS, it defaults to the directory from which Emacs was started, with /bin removed from the end if it was present. On Windows, the default value of HOME is C:/, the root directory of drive C:.
The name of the machine that Emacs is running on.
A colon-separated list of directories. Used by the complete package to search for files.
A colon-separated list of directories in which to search for Info files.
The user's preferred locale. (The first of these environment variables with a nonempty value specifies the locale.) A locale name which contains 8859-n, 8859_n or 8859n, where n is between 1 and 4, automatically specifies the Latin-n language environment when Emacs starts up. There are a few extensions: if n is 9, that specifies Latin-5, and if n is 14 or 15, that specifies Latin-8 and Latin-9, respectively.
The locale value you specify with one of these three variables is matched against entries in locale-language-names, locale-charset-language-names, and locale-preferred-coding-systems, to select a default language environment and coding system. Section 20.3.
The user's login name. See also USER.
The name of the user's system mail inbox.
Name of file containing mail aliases. (The default is ~/.mailrc.)
Name of setup file for the mh system. (The default is ~/.mh_profile.)
The real-world name of the user.
The name of the news server. Used by the mh and Gnus packages.
The name of the organization to which you belong. Used for setting the `Organization:' header in your posts from the Gnus package.
A colon-separated list of directories in which executables reside. This is used to initialize the Emacs Lisp variable exec-path.
If set, this should be the default directory when Emacs was started.
If set, this specifies an initial value for the variable mail-default-reply-to. Section 28.2.
The name of a directory in which news articles are saved by default. Used by the Gnus package.
The name of an interpreter used to parse and execute programs run from inside Emacs.
The name of the terminal that Emacs is running on. The variable must be set unless Emacs is run in batch mode. On MS-DOS, it defaults to internal, which specifies a built-in terminal emulation that handles the machine's own display. If the value of TERM indicates that Emacs runs in non-windowed mode from xterm or a similar terminal emulator, the background mode defaults to light, and Emacs will choose colors that are appropriate for a light background.
The name of the termcap library file describing how to program the terminal specified by the TERM variable. This defaults to /etc/termcap.
Used by the Emerge package as a prefix for temporary files.
This specifies the current time zone and possibly also daylight saving time information. On MS-DOS, if TZ is not set in the environment when Emacs starts, Emacs defines a default value as appropriate for the country code returned by DOS. On MS-Windows, Emacs does not use TZ at all.
The user's login name. See also LOGNAME. On MS-DOS, this defaults to root.
Used to initialize the version-control variable (Section 18.104.22.168).
These variables are used only on particular configurations:
On MS-DOS and MS-Windows, the name of the command interpreter to use when invoking batch files and commands internal to the shell. On MS-DOS this is also used to make a default value for the SHELL environment variable.
On MS-DOS, this variable defaults to the value of the USER variable.
On MS-DOS and MS-Windows, these specify the name of the directory for storing temporary files in.
On MS-DOS, this specifies a file to use to log the operation of the internal terminal emulator. This feature is useful for submitting bug reports.
On MS-DOS, this specifies the screen colors. It is useful to set them this way, since otherwise Emacs would display the default colors momentarily when it starts up.
The value of this variable should be the two-character encoding of the foreground (the first character) and the background (the second character) colors of the default face. Each character should be the hexadecimal code for the desired color on a standard PC text-mode display. For example, to get blue text on a lightgray backgraound, specify EMACSCOLORS=17, since 1 is the code of the blue color and 7 is the code of the lightgray color.
The PC display usually supports only eight background colors. However, Emacs switches the DOS display to a mode where all 16 colors can be used for the background, so all four bits of the background color are actually used.
Used when initializing the Sun windows system.
Here and below, whenever we say "colon-separated list of directories", it pertains to Unix and GNU/Linux systems. On MS-DOS and MS-Windows, the directories are separated by semi-colons instead, since DOS/Windows file names might include a colon after a drive letter.