How to Set Up Environment Variables in Windows 11
- 20 steps
- Needs administrator rights
- Includes a restart or sign-out
An environment variable is a named text value that tells programs where to find folders, files and system settings on your PC. To open the settings, right-click Start, choose System, click Advanced system settings, then click Environment Variables… on the Advanced tab.
Custom tools, programming languages and batch scripts (text files of commands that run in order) rely on environment variables to work properly. Windows uses built-in variables too, so apps don’t have to guess a path like 📁C:\
The Environment Variables window sits inside System Properties, the classic Windows screen for these settings. Adding one variable takes under a minute. Command Prompt and PowerShell can do the same job if you prefer a terminal.
To set an environment variable in Windows 11, right-click Start, choose System, click Advanced system settings, then click Environment Variables on the Advanced tab. Under User variables, click New, enter a Variable name such as MY_FOLDER and a Variable value such as 📁C:\
What Are Environment Variables?
An environment variable is a name paired with a value. Windows hands these pairs to every program you start, and each program looks up a name to get its value. Nobody has to type a long path each time.
For example, you can store your working folder in a variable called MY_FOLDER. A script asks for MY_FOLDER and gets the path. If you move the folder, you change the variable once instead of editing every script.
Some variables exist from the start. Path is the best known: it is the list of folders Windows searches when you type a program name in a terminal. Many installers for programming languages and developer tools add their own folder to it. Variable names are not case-sensitive, so My_Folder and MY_FOLDER are the same name.
Variables come in two scopes:
- User variable – applies only to your account. It never affects anyone else who signs in to the PC.
- System variable – applies to every account on the PC. You need administrator rights to change it.
Programs read their variables when they start, so a change doesn’t reach a program that is already open.
Ways to Set Environment Variables in Windows 11
You can create environment variables in three ways:
- System Properties – a graphical screen with buttons and text boxes. It is the friendliest option and the best place to start.
- Command Prompt – a text-based tool where you type commands. It suits quick changes and batch files.
- PowerShell – a more advanced command tool, suited to scripts and automation.
All three change the same stored values. A variable created in one place appears in the others, so use whichever you prefer.
1Using System Properties (Easy Way)
System Properties lets you add, edit or delete user and system variables without typing commands. It works the same on Home and Pro editions of a currently supported Windows 11 version (25H2 or 26H2).
These steps open the Environment Variables window, then add a variable to your account or to the whole PC.
- Right-click the Start button. A menu of system shortcuts opens above the taskbar.
- Select System. Settings opens on System About.
- Click Advanced system settings under the related links on the right. If Windows asks for administrator approval, click Yes. The System Properties window opens.

- Check that System Properties is on the Advanced tab. If it isn’t, click Advanced at the top.
- Click the Environment Variables… button near the bottom of the window.

The window shows two lists:
- User variables – These affect only your account. The list title includes your account name.
- System variables – These affect every user on the computer.
To add a variable:
- Click New… under the list you want, User variables or System variables. ⚠️ Admin privileges required for System variables. A small dialog opens with two boxes.
- Type a name in the Variable name box, such as MY_FOLDER.
- Type the value in the Variable value box, such as 📁C:\
Users\ . For a folder, you can click Browse Directory… and pick it instead, which avoids typos.USERNAME\ Documents - Click OK. The new variable appears in the list.

- Click OK in the Environment Variables window. This saves the change and returns you to System Properties.
- Click OK in System Properties. Closing the windows with the X discards your changes.
The variable is now stored, for your account only or for every user, depending on the list you chose.
Programs that are already open don’t see the change. Close and reopen them, or sign out and back in. Restart the PC if a program still doesn’t pick up the value.
To edit or remove a variable later, open the same window, select the variable and click Edit… or Delete. Leave the built-in variables alone unless you know what you are changing, especially Path.
2Using Command Prompt
The setx command saves a permanent variable from a typed command. A user variable doesn’t strictly need administrator rights, but the system-wide option does. Open an administrator window from the start to cover both.
These steps open an administrator Command Prompt and set a user variable, then a system-wide one.
- Right-click the Start button and select Windows Terminal (Admin). On some builds the entry is labeled Terminal (Admin). ⚠️ Admin privileges required.
- Click Yes if the User Account Control prompt appears. A terminal window opens, usually on a PowerShell tab.
- Click the down arrow next to the “+” tab and choose Command Prompt. A new tab opens with a Command Prompt.
- Type this command to create a user variable, then press Enter:Command Prompt
setx VARIABLE_NAME "VARIABLE_VALUE"
Replace VARIABLE_NAME with your variable’s name and VARIABLE_VALUE with the value. Keep the value in quotation marks if it contains spaces. A message saying the value was saved means it worked.Example:
Command Promptsetx Downloads "C:\Users\UserName\Downloads" - Type this command to create a system-wide variable for all users, then press Enter:Command Prompt
setx /M VARIABLE_NAME "VARIABLE_VALUE"
⚠️ Admin privileges required for the /M flag. Without administrator rights, the command fails with an access error.Example:
Command Promptsetx /M Downloads "C:\Users\UserName\Downloads"
The variable is now saved permanently, as a user or system variable depending on the command you used.
The setx command doesn’t change the window you typed it in. Open a new Command Prompt window to use the variable. If a program still doesn’t see it, restart that program or the PC.
3Using Windows PowerShell
PowerShell sets variables with commands and suits scripts. As with Command Prompt, a user variable doesn’t strictly need administrator rights, but the Machine scope (the setting that applies to the whole PC) does.
These steps set a user variable, then a system-wide one, from a PowerShell tab.
- Open Windows Terminal (Admin) as shown above. ⚠️ Admin privileges required.
- Check that you are in a PowerShell tab. It opens by default, and the tab title says Windows PowerShell or PowerShell.
- Type this command to create a user variable, then press Enter:Code
::SetEnvironmentVariable("VARIABLE_NAME", "VARIABLE_VALUE", "User")Example:
Code::SetEnvironmentVariable("Downloads","C:\Users\UserName\Downloads","User") - Type this command to create a system-wide variable, then press Enter:Code
::SetEnvironmentVariable("VARIABLE_NAME", "VARIABLE_VALUE", "Machine")
⚠️ Admin privileges required for the Machine scope, which applies to every user on the PC.Example:
Code::SetEnvironmentVariable("Downloads","C:\Users\UserName\Downloads","Machine")
PowerShell has now stored the variable permanently. Any new window you open can use it.
New PowerShell or Command Prompt windows see the change. Windows that were already open may not. Restart those programs, or the PC, to apply it fully.
How to Check if Your Variable Was Created
Open a new window after making the change, then print the variable:
- In Command PromptType
echo %VARIABLE_NAME%and press Enter. - In PowerShellType
$env:VARIABLE_NAMEand press Enter.
You should see the value you set. If you see nothing, or Command Prompt prints the variable name back with percent signs, that window can’t see the variable. Close it, open a new one and try again.
If the variable still fails, open the Environment Variables window and compare the name with what you typed. A typo in the name is the most common cause. Select the variable, click Edit… to correct the name or value, click OK in both windows, then test again from a new window.
Summary
To undo a variable, open Environment Variables, select it in its list and click Del. If a program still can’t see a variable, open a new window and compare the variable’s name with what you typed. To change Path, use the Edit button in the Environment Variables window rather than setx.
Have a question about this guide?
Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.
Did this guide fix your problem?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
No comments yet — be the first to share your thoughts!