3 Ways to Set & Edit Environment Variables on Windows 11
It's easier than you think & more powerful than you know!
5 min. read
Updated on
Read our disclosure page to find out how can you help Windows Report sustain the editorial team. Read more
Setting environment variables on Windows 11 can help you customize your system, run scripts, and configure applications.
In this guide, we will discuss three ways with step-by-step instructions to do that so you can configure your system according to your preferences. But first:
Types of Environment Variables
There are three types of Environment Variables:
- System Environment Variables – The global variables are at the lowest priority, can be accessed by all users & apps on a Windows, and are usually used to define system-wide settings.
- User Environment Variables – With a higher priority, these only apply to the current user & processes running under that account & are set by the user or apps that run under that account.
- Process Environment Variables – With the highest priority, they are temporary and apply to the current process & its child processes, providing runtime information or customization for a program.
How do I set & use Environment Variables on Windows 11?
1. Using the Settings app
- Press Windows + I to open Settings.
- Go to System, then click About.
- Click the Advanced system settings link.
- On the System Properties window, click Environment Variables.
- Next, on the Environment Variables window, you will see two types of variables. Choose an option from either User variables for user or System variables and click New.
- On the following window, type in the Variable name without any spaces, and for Variable Value, click the Browse Directory or Browse File button.
- Select the path and click OK.
2. Using the Command Prompt
- Press the Windows key, type cmd in the search bar, and click Run as administrator.
- To add a temporary variable to your system, use this command after replacing VariableName & Variablevalue with the one you want and hit Enter:
set VariableName = Variablevalue
- The set command is used to define an environment variable within the process for which it is defined and will be deleted once the window is closed.
- To set environment variables permanently, type the following command after replacing the Variablename with the name of the variable & Value with the value you want to set and press Enter:
setx Variablename Value /m
- Now for the path variables, type the following command to list all of them and hit Enter:
echo %PATH%
- Copy & paste the following command to add another variable to the path directory; replace the PATH value with the path you want to add and press Enter:
setx PATH "%PATH%; PATH Value
- Refresh the Environment variable window to see the newly added path.
3. Using the Windows PowerShell
- Press the Windows key, type powershell, and click Run as administrator.
- Type the following command to list of path variables and press Enter: [Environment]::GetEnvironmentVariable(“PATH”)
- Copy & paste the following command to declare a path variable after replacing PATH with the path you want to add and hit Enter:
$Variable_Name = "PATH"
- To add the variable to the Path Variable list, use this command after replacing Folder PATH with the path you declared and press Enter: [Environment]::SetEnvironmentVariable(“Folder PATH”, “$PATH;$Variable_Name”)
- Restart your computer to let the changes take effect.
You can use any of the methods to add a new or missing environment variable to prevent issues like the system could not find the environment option that was entered
How do I edit Environment Variables on Windows 11?
1. Using the Settings app
- Press Windows + I to open Settings, then go to System > About >Advanced system settings.
- Click Environment Variables, then select the variable you want to edit and click Edit.
- Make the changes and click OK on all three windows to save the changes.
- Restart the Environment Variable window to see the changes.
2. Using the Registry Editor
- Press Windows + R to open the Run dialog box.
- Type regedit and click OK to open Registry Editor.
- Navigate to this path if you are making changes to User Variables:
Computer\HKEY_CURRENT_USER\Environment
- For System Variables, go to this path:
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
- Once you have located either of the variables, you can change the name by right-clicking and selecting Rename.
- To edit the value, double-click the variable, change the Value data, and click OK.
- Restart your computer to save the changes.
3. Using the Windows PowerShell
- Open Windows PowerShell with administrator privileges using the same steps mentioned above.
- Type the following command to get the current value of the variable after replacing VARIABLENAME with the variable name and press Enter:
$Env: VARIABLENAME
- Next, to update or edit the value, copy & paste the following command after replacing the VARIABLEANME with the name of the variable & NEWVALUE with the value that you want to add, then hit Enter:
$Env: VARIABLENAME = "NEWVALUE"
- Reboot your PC to save the changes.
How do I get a list of Environment Variables in Windows?
To get a list of environment variables in Windows 11, you can open Command Prompt with administrator rights and type set, and hit Enter.
In Powershell, with admin privileges to get a list of environment variables, copy & paste the following command and hit Enter: [System.Environment]::GetEnvironmentVariables()
If you want to print the environment variables list you got on PowerShell to apply the same settings on another computer, read this guide.
Where are Windows environment variables stored?
You can find the environment variables in Registry Editor. The system variables are found in Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment, wherein the user variables are located at Computer\HKEY_CURRENT_USER\Environment
Setting environment variables on Windows 11 can help you customize your system settings; however, you must always exercise caution when making changes to system variables.
Remember to double-check the variable name & value, and always create a backup of your registry editor before making changes.
Stuck somewhere? Don’t hesitate to mention your queries in the comments section below. We will be happy to assist you.
User forum
0 messages