Home >
Common Problem >
11 Ways to Set Environment Variables on Windows 3
11 Ways to Set Environment Variables on Windows 3
PHPz
Release: 2023-09-15 12:21:10
forward
1788 people have browsed it
Setting environment variables on Windows 11 can help you customize your system, run scripts, and configure applications.
In this guide, we'll discuss three methods along with step-by-step instructions so you can configure your system to your liking.
There are three types of environment variables
System Environment Variables – Global variables are the lowest priority, accessible to all users and applications on Windows, and are typically used to define system-wide settings.
User Environment Variables – The higher the priority, these variables only apply to the current user and process running under that account, and are set by the user or application running under that account .
Process Environment Variables – With the highest priority, they are temporary and apply to the current process and its sub-processes, providing runtime information or customization to the program.
How to set and use environment variables on Windows 11?
1. Using the Settings app
press to open Settings. WindowsI
Go to System and click About.
Click the Advanced System Settings link.
In the "System Properties" window, click "Environment Variables".
Next, in the Environment Variables window, you will see two types of variables. Select an option from User Variables in User or System Variables and click New.
In the following window, type the variable name without any spaces, and for the variable value, click the Browse Directory or Browse for File button.
Select the path and click OK.
2. Use the Command Prompt
key, type cmd in the search bar, and click Run as administrator. Windows
To add a temporary variable to the system, use this command after replacing the variable name and variable value with the desired variable and hit: Enter <strong>set VariableName = Variablevalue</strong>
set command is used to define an environment variable in the process, which is ignored , and is deleted after the window is closed.
To set an environment variable permanently, type the following command after replacing Variablename with the variable name and Value with the value you want to set, and then press: Enter<strong> setx Variablename Value /m</strong>
Type the following command to list path variables and click: Enter<strong>echo %PATH%</strong>
Copy and 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<strong>setx PATH "%PATH%; PATH Value</strong>
Refresh the "Environment Variables" window to see the newly added path.
3. Use Windows PowerShell
key, type PowerShell, and then click Run as administrator. Windows
Type the following command to list path variables and press: [Environment]::GetEnvironmentVariable("PATH") Enter
Copy and paste the following command to replace PATH in Declare a path variable after the path to be added and clicked: Enter<strong>$Variable_Name = "PATH"</strong>
To change the variable To add to the list of path variables, use this command after replacing the folder PATH with the path you declared and press: [Environment]::SetEnvironmentVariable("folder PATH", "$PATH;$Variable_Name") Enter
Restart the computer for the changes to take effect.
You can use any method to add new or missing environment variables to prevent the system from Problems such as input environment options not found
How to edit environment variables on Windows 11?
1. Using the Settings app
Press to open Settings, then go to System, then About ,Then click "Advanced System Settings". WindowsI
Click Environment Variables, then select the variable you want to edit and click Edit.
Make your changes and click OK in all three windows to save your changes.
Restart the Environment Variables window to see the changes.
2. Use the Registry Editor
Press to open the "Run" dialog box. WindowsR
Type regedit and click OK to open Registry Editor .
If you want to change user variables, navigate to this path: <strong>Computer\HKEY_CURRENT_USER\Environment</strong>
For system variables, go to Go to the following path: <strong>Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment</strong>
If you want to rename the variable name, right click and select "Rename".
To edit the value data, double-click the variable, change the value data, and click OK.
Restart your computer to save changes.
3. Use Windows PowerShell
Use the same steps above to open Windows PowerShell with administrator privileges.
Type the following command to get the current value of a variable. After replacing VARIABLENAME with the variable name, press: Enter<strong>$Env: VARIABLENAME</strong>
Next, to update or edit the value, copy and paste the following command after replacing VARIABLEANME with the variable name and NEWVALUE with the value you want to add, then click: Enter<strong>$Env: VARIABLENAME = "NEWVALUE"</strong>
Restart your computer to save changes.
How to get the list of environment variables in Windows?
To get a list of environment variables in Windows 11, you can open a command prompt with administrator rights and type Settings and hit .Enter
In Powershell, with administrator rights to get a list of environment variables, copy and paste the following command and hit: Enter<strong>[System. Environment]::GetEnvironmentVariables()</strong>
Read this guide if you want to print the list of environment variables obtained on PowerShell to apply the same settings on another computer.
Where are Windows environment variables stored?
You can find environment variables in the Registry Editor. System variables are located in Computer\HKEY_LOCAL_MACHINE\System\Current Control Set\Control\Session Manager\Environment, where user variables are located in <strong>Computer\HKEY_CURRENT_USER\Environment</strong>
Setting environment variables on Windows 11 can help you customize system settings; however, you must always be careful when changing system variables.
Remember to double-check variable names and values, and always create a backup of Registry Editor before making changes.
The above is the detailed content of 11 Ways to Set Environment Variables on Windows 3. For more information, please follow other related articles on the PHP Chinese website!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn