cmd.exe: Show/Set Environment Variable

By Xah Lee. Date: . Last updated: .

For introduction, see Windows Environment Variable Tutorial

Windows environment variable names are not case sensitive

Show Single Environment Variable's Value

To show a value of a env var, type echo %env_var_name%.

For example:

echo %path%

Show All Environment Variables

In Command Prompt (cmd.exe), type set

To see all your env vars, type:

set
cmdexe environment variable 2017 05 08
cmd.exe showing environment variables, by set

To see all env vars starting with “p”, type:

set p

Set Environment Variable for Current Session

To set env var for the current session, use set var_name=value. WARNING: make sure there is no space around the equal sign. Example:

set xx=5
echo %xx%
REM prints 5. (REM is a comment syntax, everything after it is ignored.)
REM prepending a path to the “path” env var 
set PATH="C:\Program Files (x86)\ErgoEmacs;%PATH%"

Set Environment Variable Permanently in Registry

To set env var permanently, use “setx” command. The “setx” command is part of “cmd.exe” in Windows Vista. Here's a example:

REM example of setting HOME env var
setx HOME "C:\Users\mary"
REM example of adding a path
setx PATH "C:\Program Files (x86)\ErgoEmacs;%PATH%"

For detail, type setx /?.

Note: “setx” sets environment variable in the registry, but does not update the current session. Exit and start a new cmd.exe console to see them.