Environment Variables
Overview
All Windows environment variables are imported when Cygwin starts.
Apart from that, you may wish to specify settings of several important
environment variables that affect Cygwin's operation.
The CYGWIN variable is used to configure a few global
settings for the Cygwin runtime system. Typically you can leave
CYGWIN unset, but if you want to set one ore more
options, you can set it using a syntax like this, depending on the shell
in which you're setting it. Here is an example in CMD syntax:
C:\> set CYGWIN=error_start:C:\cygwin\bin\gdb.exe glob
This is, of course, just an example. For the recognized settings of the
CYGWIN environment variable, see
.
Locale support is controlled by the LANG and
LC_xxx environment variables. For a more detailed description
see .
The PATH environment variable is used by Cygwin
applications as a list of directories to search for executable files
to run. This environment variable is converted from Windows format
(e.g. C:\Windows\system32;C:\Windows) to UNIX format
(e.g., /cygdrive/c/Windows/system32:/cygdrive/c/Windows)
when a Cygwin process first starts.
Set it so that it contains at least the x:\cygwin\bin
directory where "x:\cygwin is the "root" of your
cygwin installation if you wish to use cygwin tools outside of bash.
This is usually done by the batch file you're starting your shell with.
The HOME environment variable is used by many programs to
determine the location of your home directory. This environment variable,
if it exists, is converted from Windows format when a Cygwin process first
starts. However, it's usually set in the shell profile scripts in the /etc
directory, and it's not recommended to set
the variable in your Windows environment.
The TERM environment variable specifies your terminal
type. It is automatically set to cygwin if you have
not set it to something else.
The LD_LIBRARY_PATH environment variable is used by
the Cygwin function dlopen () as a list of
directories to search for .dll files to load. This environment variable
is converted from Windows format to UNIX format when a Cygwin process
first starts. Most Cygwin applications do not make use of the
dlopen () call and do not need this variable.
The GMON_OUT_PREFIX environment variable is helpful
in some situations when profiling Cygwin programs. For more information,
see . Only software developers with a
need to profile their programs have a use for this variable.
In addition to PATH, HOME,
LD_LIBRARY_PATH, and GMON_OUT_PREFIX,
there are three other environment
variables which, if they exist in the Windows environment, are
converted to UNIX format: TMPDIR, TMP,
and TEMP. The first is not set by default in the
Windows environment but the other two are, and they point to the
default Windows temporary directory. If set, these variables will be
used by some Cygwin applications, possibly with unexpected results.
You may therefore want to unset them by adding the following two lines
to your ~/.bashrc file:
unset TMP
unset TEMP
This is done in the default ~/.bashrc file.
Alternatively, you could set TMP
and TEMP to point to /tmp or to
any other temporary directory of your choice. For example:
export TMP=/tmp
export TEMP=/tmp
Restricted Win32 environment
There is a restriction when calling Win32 API functions which
require a fully set up application environment. Cygwin maintains its own
environment in POSIX style. The Win32 environment is usually stripped
to a bare minimum and not at all kept in sync with the Cygwin POSIX
environment.
If you need the full Win32 environment set up in a Cygwin process,
you have to call
#include <sys/cygwin.h>
cygwin_internal (CW_SYNC_WINENV);
to synchronize the Win32 environment with the Cygwin environment.
Note that this only synchronizes the Win32 environment once with the
Cygwin environment. Later changes using the setenv
or putenv calls are not reflected in the Win32
environment. In these cases, you have to call the aforementioned
cygwin_internal call again.