This tutorial will show you how to set (create) new user and system environment variables in Windows 10 and Windows 11.
Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer. The variables can be used both in scripts and on the command line. Environment variables makes it easy when certain standard directories and parameters need to be referenced but where the actual locations or names can vary from computer to computer.
The variable (ex: "%UserProfile%" for command and "$Env:UserProfile" for PowerShell) is used as a type of shortcut of the value (ex: "C:\Users\<username>").
There are two types of environment variables: user environment variables (set only for current user) and system (machine) environment variables (set for all users).
User environment variables are stored in the registry key below:
HKEY_CURRENT_USER\Environment
System environment variables are stored in the registry key below:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
You can open a command prompt, type set
, and press Enter to display all current environment variables on your PC.
You can open PowerShell, type Get-ChildItem Env:
, and press Enter to display all current environment variables on your PC.
- Option One: Create New User Environment Variables in Environment Variables
- Option Two: Create New User Environment Variables using "setx" Command
- Option Three: Create New User Environment Variables in PowerShell
- Option Four: Create New System Environment Variables in Environment Variables
- Option Five: Create New System Environment Variables using "setx" Command
- Option Six: Create New System Environment Variables in PowerShell
1 Open the Control Panel (icons view), and click/tap on the User Accounts icon.
2 Click/tap on the Change my environment variables link on the left side, and close the User Accounts control panel window if you like. (see screenshot below)
This opens rundll32.exe sysdm.cpl,EditEnvironmentVariables
.
3 Click/tap on the New button under the top User variables for <current user name> section. (see screenshot below)
4 Perform the steps below: (see screenshot below)
- Enter a Variable name (ex: "Downloads") you want used as the environment variable (ex: "%Downloads%" or "$Env:Downloads").
- Enter a Variable value (ex: "C:\Users\Brink\Downloads") you want referenced by the environment variable.
- Click/tap on OK.
If you like, you could click/tap on the Browse Directory button to navigate to and select a directory to have its path entered for the variable value.
If you like, you could click/tap on the Browse File button to navigate to and select a file to have its path entered for the variable value.
5 When finished creating new user variables for your account, click/tap on OK to apply (set) the new variables. (see screenshot below)
1 Open Windows Terminal, and select either Windows PowerShell or Command Prompt.
2 Type the command below into Windows Terminal, and press Enter. (see screenshot below)
setx [variable name] "[variable value]"
Substitute [variable name] in the command above with the actual variable name (ex: "Downloads") you want used as the environment variable (ex: "%Downloads%" or "$Env:Downloads").
Substitute [variable value] in the command above with the actual variable value (ex: "C:\Users\Brink\Downloads") you want referenced by the environment variable.
For example: setx Downloads "C:\Users\Brink\Downloads"
3 You can now close Windows Terminal if you like.
1 Open Windows Terminal, and select Windows PowerShell.
2 Type the command below into Windows Terminal, and press Enter. (see screenshot below)
[Environment]::SetEnvironmentVariable("[variable name]","[variable value]","User")
Substitute [variable name] in the command above with the actual variable name (ex: "Downloads") you want used as the environment variable (ex: "%Downloads%" or "$Env:Downloads").
Substitute [variable value] in the command above with the actual variable value (ex: "C:\Users\Brink\Downloads") you want referenced by the environment variable.
For example: [Environment]::SetEnvironmentVariable("Downloads","C:\Users\Brink\Downloads","User")
3 You can now close Windows Terminal if you like.
You must be signed in as an administrator to use this option
1 Open Advanced System Properties (SystemPropertiesAdvanced.exe).
2 Click/tap on the Environment Variables button. (see screenshot below)
3 Click/tap on the New button under the bottom System variables section. (see screenshot below)
4 Perform the steps below: (see screenshot below)
- Enter a Variable name {ex: "Downloads") you want used as the environment variable (ex: "%Downloads%" or "$Env:Downloads").
- Enter a Variable value (ex: "%UserProfile%\Downloads") you want referenced by the environment variable.
- Click/tap on OK.
If you like, you could click/tap on the Browse Directory button to navigate to and select a directory to have its path entered for the variable value.
If you like, you could click/tap on the Browse File button to navigate to and select a file to have its path entered for the variable value.
5 When finished creating new system variables, click/tap on OK to apply (set) the new variables. (see screenshot below)
6 Click/tap on OK. (see screenshot below)
You must be signed in as an administrator to use this option
1 Open Windows Terminal (Admin), and select Windows PowerShell.
2 Type the command below into Windows Terminal (Admin), and press Enter. (see screenshot below)
setx [variable name] "[variable value]" /m
Substitute [variable name] in the command above with the actual variable name (ex: "Downloads") you want used as the environment variable (ex: "%Downloads%" or "$Env:Downloads").
Substitute [variable value] in the command above with the actual variable value (ex: "%UserProfile%\Downloads") you want referenced by the environment variable.
For example: setx Downloads "%UserProfile%\Downloads" /m
3 You can now close Windows Terminal (Admin) if you like.
You must be signed in as an administrator to use this option
1 Open Windows Terminal (Admin), and select Windows PowerShell.
2 Type the command below into Windows Terminal (Admin), and press Enter. (see screenshot below)
[Environment]::SetEnvironmentVariable("[variable name]","[variable value]","Machine")
Substitute [variable name] in the command above with the actual variable name (ex: "Downloads") you want used as the environment variable (ex: "%Downloads%" or "$Env:Downloads").
Substitute [variable value] in the command above with the actual variable value (ex: "%UserProfile%\Downloads") you want referenced by the environment variable.
For example: [Environment]::SetEnvironmentVariable("Downloads","%UserProfile%\Downloads","Machine")
3 You can now close Windows Terminal (Admin) if you like.
That's it,
Shawn Brink