Настройка переменных среды Windows может помочь сократить время, необходимое для набора команд в командной строке или, если вы часто пишете скрипты для собственных задач, сделать их более читаемыми. В большинстве случаев обычные пользователи добавляют записи в системную переменную среды PATH, хотя бывают и другие задачи.
В этой пошаговой инструкции базовая информация о том, как открыть переменные среды Windows 11 и Windows 10, создать или отредактировать их.
Что такое переменные среды
Переменные среды в Windows — записи о расположении системных папок, свойствах системы и другие, которые доступны для любой программы или скрипта.
Одна из наиболее часто используемых переменных среды — PATH, указывающая на папки, в которых выполняется поиск файлов, вызываемых в командной строке, терминале Windows, файле bat или из других источников. В качестве примера её назначения:
- Если вы откроете командную строку (или диалоговое окно «Выполнить»), введёте regedit и нажмете Enter — вы сможете запустить редактор реестра, не указывая полный путь к файлу regedit.exe, поскольку путь C:\Windows добавлен в переменную среды Path.
- Если же тем же образом в командной строке написать имя программы, путь к которой не добавлен в Path (chrome.exe, adb.exe, pip и другие), вы получите сообщение «Не является внутренней или внешней командой, исполняемой программой или пакетным файлом».
Если предположить, что вы часто используете команды adb.exe (например, для установки приложений Android в Windows 11), pip install (для установки пакетов Python) или любые другие то для того, чтобы не писать каждый раз полный путь к этим файлам, имеет смысл добавить эти пути в переменные среды.
Также вы можете добавлять и иные переменные среды (не обязательно содержащие пути), а в дальнейшем получать и использовать их значения в сценариях BAT (командной строки) или PowerShell. Пример получения и отображения значения системной переменной PATH для обоих случаев:
echo %PATH% echo $Env:PATH
Получить список всех переменных среды в командной строке и PowerShell соответственно можно следующими командами:
set ls env:
Редактирование переменных среды Windows 11/10
Прежде чем приступать, учтите: изменение системных переменных среды по умолчанию может привести к проблемам в работе системы, не удаляйте уже имеющиеся переменные среды. Возможно, имеет смысл создать точку восстановления системы, если вы не уверены в своих действиях.
- Чтобы открыть переменные среды Windows вы можете использовать поиск в панели задач (начните вводить «Переменных» и откройте пункт «Изменение системных переменных среды») или нажать клавиши Win+R на клавиатуре, ввести sysdm.cpl и нажать Enter.
- На вкладке «Дополнительно» нажмите кнопку «Переменные среды…»
- В разделе «Переменные среды пользователя» (если требуется изменение только для текущего пользователя) или «Системные переменные» выберите переменную, которую нужно изменить и нажмите «Изменить» (обычно требуется именно это), либо, если необходимо создать новую переменную — нажмите кнопку «Создать». В моем примере — добавляем свои пути в системную переменную Path (выбираем эту переменную и нажимаем «Изменить»).
- Для добавления нового значения (пути) в системную переменную в следующем окне можно нажать кнопку «Создать», либо просто дважды кликнуть по первой пустой строке, затем — ввести нужный путь к папке, содержащей нужные нам исполняемые файлы.
- Также вы можете использовать кнопку «Изменить текст», в этом случае окно изменения системной переменной откроется в ином виде: имя переменной, а ниже — её значение. В случае указания путей значение будет представлять собой все пути, хранящиеся в переменной, разделенные знаком «точка с запятой».
- При создании новой переменной среды окно будет тем же, что и в 5-м шаге: необходимо будет указать имя системной переменной в верхнем поле, а её значение — в нижнем.
После создания или изменения переменной среды и сохранения сделанных настроек, переменная или обновленные значения сразу становятся доступны для текущего пользователя или в системе в целом в зависимости от того, какие именно переменные редактировались или создавались. Также есть методы добавления переменных среды в командной строке или PowerShell, подробнее в статье: Как добавить путь в переменную среды PATH
Environment variables in an operating system are values that contain information about the system environment, and the currently logged in user. They existed in OSes before Windows as well, such as MS-DOS. Applications or services can use the information defined by environment variables to determine various things about the OS, for example, to detect the number of processes, the currently logged in user’s name, the folder path to the current user’s profile or the temporary files directory. Today, we will review a number of methods you can use to create a new user and system environment variable in Windows 10.
Windows 10 has several types of environment variables: user variables, system variables, process variables and volatile variables. User environment variables are accessible to all apps which run in the current user context, system environment variables apply to all users and processes on the PC; process variables are applicable only to a specific process and volatile variables are those which exist only for the current logon session. Most interesting of these are user, system and process variables, as we can modify them.
Example: A user environment variable.
Example: A system environment variable.
Windows 10 stores user environment variables under the following Registry key:
HKEY_CURRENT_USER\Environment
System variables are stored under the following key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
Reference: How to see names and values of environment variables in Windows 10
- Open the classic Control Panel.
- Navigate to Control Panel\User Accounts\User Accounts.
- On the left, click on the Change my environment variables link.
- In the next dialog, click the New button under the User variables for <username> section.
- Enter a variable name you want to create, then enter a variable value you want to assign to it. The dialog allows browsing for a file or folder to save your time.
- Click the OK button, and you are done.
Note: Re-open the required apps (e.g. Command Prompt) to make them read your new environment variable.
Tip: There are a number of other methods you can use to open the environment variables editor in Windows 10. First of all, you can create a special shortcut to open it directly. See Create Environment Variables Shortcut in Windows 10.
Also, there’s a special RunDLL command that you can use (Press Win + R and copy-paste it to the Run box):
rundll32.exe sysdm.cpl,EditEnvironmentVariables
Finally, you can right-click the This PC icon in File Explorer and select Properties from the context menu. Click the «Advanced System Settings» link on the left. In the next dialog, «System Properties», you will see the Environment Variables… button in the bottom of the Advanced tab. Moreover, the Advanced System Settings dialog can be directly opened with the systempropertiesadvanced
command entered into the Run dialog.
Create a User Environment Variable in Command Prompt
- Open a new command prompt
- Type the following command:
setx <variable_name> "<variable_value>"
- Substitute
<variable_name>
with the actual name of the variable you want to create. - Substitute
"<variable_value>"
with the value you want to assign to your variable.
Do not forget to restart your apps (e.g. Command Prompt) to make them read your new environment variable.
The setx command is a console tool that can be used to set or unset user and system environment variables. In the general case, the syntax is as follows:
setx variable_name variable_value
— set an environment variable for the current user.
setx /M variable_name variable_value
— set an environment variable for all user (system-wide).
Type setx /? in a command prompt to see more details about this tool.
Create a User Environment Variable in PowerShell
- Open PowerShell.
- Type the following command:
[Environment]::SetEnvironmentVariable("<variable_name>", "<variable_value>" ,"User")
- Substitute
<variable_name>
with the actual name of the variable you want to create. - Substitute
"<variable_value>"
with the value you want to assign to your variable.
Similarly, you can create a system environment variable.
Create a System Environment Variable
- Open the Run dialog (Win + R), and execute the command
systempropertiesadvanced
. - In the System Properties dialog, switch to the Advanced tab. Click on the Environment Variables… button.
- In the next dialog, click the New button under the System variables section.
- Set the desired name for a variable you want to create, and specify its value, then click OK.
Create a User Environment Variable in Command Prompt
- Open a new command prompt as Administrator.
- Type the following command:
setx /M <variable_name> "<variable_value>"
- Substitute
<variable_name>
with the actual name of the variable you want to create. - Substitute
"<variable_value>"
with the value you want to assign to your variable.
The /M switch makes the setx command create a system variable.
Create a System Environment Variable in PowerShell
- Open PowerShell as Administrator. Tip: You can add «Open PowerShell As Administrator» context menu.
- Type the following command:
[Environment]::SetEnvironmentVariable("<variable_name>", "<variable_value>" ,"Machine")
- Substitute
<variable_name>
with the actual name of the variable you want to create. - Substitute
"<variable_value>"
with the value you want to assign to your variable.
The last parameter of the SetEnvironmentVariable call tells it to register the given variable as a system variable.
That’s it.
Related articles:
- Create Environment Variables Shortcut in Windows 10
- How to see names and values of environment variables in Windows 10
- See names and values of environment variables for a process in Windows 10
Support us
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
If you like this article, please share it using the buttons below. It won’t take a lot from you, but it will help us grow. Thanks for your support!
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).
Contents
- 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
Option One
Create New User Environment Variables in Environment Variables
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)
Option Two
Create New User Environment Variables using «setx» Command
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.
Option Three
Create New User Environment Variables in PowerShell
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.
Option Four
Create New System Environment Variables in Environment Variables
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)
Option Five
Create New System Environment Variables using «setx» Command
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.
Option Six
Create New System Environment Variables in PowerShell
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
Environment variables are user variables or Windows system variables that describe the environment in which apps run. They can tell your apps things like the name of the computer, the name of the user account, the current working directory, etc. Do you want to know more about how to use environment user variables and Windows system variables? If you do, read this tutorial and learn how to create environment variables in Windows 11 and Windows 10. There are some situations when knowing how to do that can prove very useful.
Things you should know before creating environment variables in Windows
There are two things you should know before following any of the steps shown in this guide to create user and system variables pointing to a folder, file, or anything else. The first and the most important one is to understand what environment variables are. Secondly, you should know the differences in user variables vs. system variables in order to be able to decide what kind of variable you should create. For answers and explanations on these matters, I recommend you read this article before going ahead with the instructions below: What are environment variables in Windows?.
Environment user and system variables in Windows
Then, once you understand what environment variables are and once you know what type of variable you want to create, you’ll have to open the Environment Variables window. If you’ve read the tutorial I recommended in the previous paragraph, you already know how to do it. However, if you didn’t have time for that, know that an easy method of launching the Environment Variables is to use the search.
If you’re using Windows 11, click or tap the search box (or button) on your taskbar, type environment, and click or tap the “Edit the system environment variables” result.
How to open the Environment Variables in Windows 11
The same applies to Windows 10. Click or tap on the search box on the taskbar, enter environment in the search box, and select “Edit the system environment variables” in the list of results.
How to open the Environment Variables in Windows 10
Then, the steps to create user variables or system variables are the same regardless of the operating system you’re using. As you can see in the next picture, even the Environment Variables window is identical in Windows 11 and Windows 10.
Environment Variables in Windows 11 vs Windows 10
Without further ado, here are the steps to create environment user variables and system variables in Windows:
How to create environment user variables in Windows
User environment variables are available only to your user account. When creating such variables, their values should include paths towards locations that are accessible to your user account. For example, you can’t have your user variable point to a personal folder of another user account (like Documents, Pictures, Music, etc.). In the “User variables for [user account]” section, click or tap New.
The Environment Variables window
The “New User Variable” window opens. Start by typing the name of the variable you want to create (1). Make it something suggestive to easily remember its purpose. Then, type its value (2). The value may include a path or more. A path can point to a folder or a file. You can also use other existing variables to build up the path you want. For example, if you want the variable to point to the folder used by Steam to save your games, you can set its value like this:
%programfiles(x86)%\Steam\steamapps\common
Entering the name and value of a new user variable
TIP: If you want your environment user variable to have more than one value, separate its values with semicolons (;) — for example, Path 1; Path 2; Path 3. Oh, and it’s not mandatory to use only paths to folders and files as values for user variables. Depending on what you want to do with the variable you create, you can also store strings (text) as its value.
When you are done setting the user variable, click or tap OK. The new variable is added to the list of user variables, but it is not yet created, so you can’t use it at this time.
The new user variable has been added to the list
To create the new user variable, click or tap OK in the Environment Variables window.
Saving the new user variable in Windows
To test if the user variable was created successfully and that it points to what you want, open a Run window (Windows + R). Type the name of the environment variable you just created between percent (%) signs. For example, to execute the steamgames variable that I just created, I have to type:
%steamgames%
Then, click or tap on OK. In my case, this action opens the folder that contains all the games I have downloaded and installed from my Steam account.
Checking a user variable in Windows
IMPORTANT: Any user can add, change, or delete user environment variables. User variables can be created by Windows 11 or Windows 10, apps, and users alike.
How to create Windows system variables
The process for creating system variables is the same as for creating user variables. To make sure you get it right, I’ll go through another quick example.
In the System variables section from the Environment Variables window, click or tap New.
Starting the process of creating a new Windows system variable
The New System Variable window opens. Enter the variable’s name (1) and value (2). In the next screenshot, for instance, you can see that I chose to create a new system variable called games that points to a folder called Games on my C: drive.
Entering the name and value of a New System Variable
TIP: Note that you can add multiple values to a variable — all you need to do is separate them with semicolons (;). Also, keep in mind that if you specify a path as a value for a system variable, that path should be accessible to all user accounts. If that path points to a location where only one user account has access, you should create a user variable instead of a system variable.
When you are done customizing the new system variable, click or tap OK. The new variable is added to the list of system variables, but it is not yet created.
The Windows system variable has been added to the list
In the Environment Variables window, click or tap OK to create the new environment variable.
Saving a new Windows system variable
To test if the system variable was created successfully, open Run (Windows + R) and insert the name of the environment system variable you created between percent (%) signs. For example, to run the games variable that I created, I must type:
%games%
Then, press the OK button.
Verifying a Windows system variable
In my case, Windows opened the Games folder where I keep most of my games. All users have access to this folder, and they can use this variable to access those games quickly.
IMPORTANT: Are you wondering whether any user can add system environment variables or change existing ones’ values? The answer is NO! Only administrators can perform these actions. Standard users don’t have enough clearance to make or change Windows system variables because they affect every user and every app on the PC. If you’re using Windows 11, this tutorial provides more details about standard and administrator accounts: How to change the Administrator account on Windows 11. And, if you have Windows 10, read this guide instead: 6 ways to change an account to Administrator and back in Windows 10.
What user variables or Windows system variables did you create?
The process involved in creating environment variables in Windows is not that complicated. Furthermore, it’s the same in Windows 11 and Windows 10. However, before you get the hang of it, you should first experiment by making a couple of safe user variables that don’t negatively impact the system’s proper operation. If you have questions about environment variables or if you have something to add to this guide, don’t hesitate to leave me a comment. Also, if you want to receive news whenever we publish new articles, do subscribe to our newsletter using the form below.
Download Article
Download Article
This wikiHow teaches how to add new environment variables in Windows 10. Environment variables are useful to specify paths internally in the OS for specific programs. It is basically stored in the form of a name and value pair. OS has a lot of builtin environment variables like ‘PATH’ where paths to installed Softwares are stored. Stick to this article, to find out how to add environment variables in Windows 10.
-
You may find it on your desktop screen. You can go to your desktop by pressing Ctrl+D.
-
2
Right-click on the «This PC» icon. This will show a small popup, with few options.
Advertisement
-
You may find this in the last position below the «Rename» option. This will open a new window with all the system details like RAM, Processor, OS, etc.
-
You may find this option on the left-hand side of the newly opened window (System Details). This option is below the «System Protection» option.
-
5
Click on Environment Variables. After clicking, it will show a new window dialog called «Environment Variables».
-
6
Decide which variable to add (User / System). Click the New option in any (User/System) section.
-
7
Add the variable name and variable value and click OK. In variable_name, you can give a name to your user variable and specify PATH in the variable_value, finally, click «ok» to save the changes.
-
After saving a new variable with path, you can see the entry of variables.
-
After clicking OK, you will have successfully created a new User variable with a PATH attached to it.
Advertisement
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement
Thanks for submitting a tip for review!
About This Article
Thanks to all authors for creating a page that has been read 26,133 times.