Windows Environment Variables Tutorial

By Xah Lee. Date: . Last updated: .

What's Environment Variables

Environment variables are system-wide global variables. They are config parameters and is used by processes. For example, apps need to know the path of your Windows kernal, path of your home dir, paths to search for shell programs, etc.

WINDOWS ENVIRONMENT VARIABLE NAMES ARE NOT CASE SENSITIVE

View Environment Variables

To view via GUI:

Windows 10 SystemPropertiesAdvanced 2021-02-04
Windows 10 SystemPropertiesAdvanced 2021-02-04

Press ❖ Window key, then type “environment”

or

Type in shell c:\Windows\System32\SystemPropertiesAdvanced.exe to launch the GUI app directly.

Sample Values of Environment Variable

Here's example of env var values as it exists on my system.

One of the most important environment variable is the PATH. Here's a sample value of path (with line break added for easy reading):

PS C:\Users\xah> $env:path -split ";"
C:\Program Files\PowerShell\7
C:\Python27\
C:\Python27\Scripts
C:\Python39\Scripts\
C:\Python39\
c:\program files\graphicsmagick-1.3.32-q8
C:\Program Files\ImageMagick-7.0.10-Q16-HDRI
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Windows\System32\OpenSSH\
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR
C:\Program Files\PowerShell\7\
C:\Program Files\Git\cmd
C:\ProgramData\chocolatey\bin
C:\Go\bin
C:\Users\xah\AppData\Local\Microsoft\WindowsApps
C:\Users\xah\AppData\Local\Programs\Microsoft VS Code\bin
C:\Users\xah\go\bin
C:\Users\xah\.deno\bin

Types of Environment Variable

There are 3 types of environment variable:

Process
Per session. It is temporary. It exist only for the current session in cmd.exe or PowerShell. After you exit the shell, the variables you created are gone. When a shell starts, it gets environment variable from the Windows Registry.
User
Permanent, stored in Windows Registry. Per user. Each user may have different values.
Examples: home folder HOMEPATH, temp dir (TEMP and or TMP).
In Registry, they are at: HKEY_CURRENT_USER\Environment.
Machine
Permanent, stored in Windows Registry. Per machine. Each machine may have different values.
Examples:
  • OS kernal path (WINDIR)
  • processor info (PROCESSOR_ARCHITECTURE, NUMBER_OF_PROCESSORS, etc)
  • application paths (PATH)
  • executable file name extensions (PATHEXT)
  • OS type (OS)
  • current user name (USERNAME)

In Registry, they are at:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
[see Microsoft Windows Registry Tutorial]

Process environment variable is also known as Local Environment Variable.

User environment variable and Machine environment variable are together also known as System Environment Variable.

Note that you can set any new env vars in any category. Programs have access to all your env vars, but which ones are meaningful to the program is up to the program.

Show/Set Environment Variables using Powershell

PowerShell: View/Set Environment Variables

Show/Set Environment Variables using cmd.exe

cmd.exe: Show/Set Environment Variable

If you have a question, put $5 at patreon and message me.