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
1747 people have browsed it

在 Windows 3 上设置环境变量的 11 种方法

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

  1. press to open Settings. WindowsI
  2. Go to System and click About. 在 Windows 3 上设置环境变量的 11 种方法
  3. Click the Advanced System Settings link. 在 Windows 3 上设置环境变量的 11 种方法
  4. In the "System Properties" window, click "Environment Variables".在 Windows 3 上设置环境变量的 11 种方法
  5. 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. 在 Windows 3 上设置环境变量的 11 种方法
  6. 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. 在 Windows 3 上设置环境变量的 11 种方法
  7. Select the path and click OK.

2. Use the Command Prompt

  1. key, type cmd in the search bar, and click Run as administrator. Windows在 Windows 3 上设置环境变量的 11 种方法
  2. 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>在 Windows 3 上设置环境变量的 11 种方法
  3. set command is used to define an environment variable in the process, which is ignored , and is deleted after the window is closed.
  4. 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>在 Windows 3 上设置环境变量的 11 种方法
  5. Type the following command to list path variables and click: Enter<strong>echo %PATH%</strong>
  6. 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>在 Windows 3 上设置环境变量的 11 种方法
  7. Refresh the "Environment Variables" window to see the newly added path.

3. Use Windows PowerShell

  1. key, type PowerShell, and then click Run as administrator. Windows在 Windows 3 上设置环境变量的 11 种方法
  2. Type the following command to list path variables and press: [Environment]::GetEnvironmentVariable("PATH") Enter
  3. 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>在 Windows 3 上设置环境变量的 11 种方法
  4. 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
  5. 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

  1. Press to open Settings, then go to System, then About ,Then click "Advanced System Settings". WindowsI
  2. Click Environment Variables, then select the variable you want to edit and click Edit. 在 Windows 3 上设置环境变量的 11 种方法
  3. Make your changes and click OK in all three windows to save your changes. 在 Windows 3 上设置环境变量的 11 种方法
  4. Restart the Environment Variables window to see the changes.

2. Use the Registry Editor

  1. Press to open the "Run" dialog box. WindowsR在 Windows 3 上设置环境变量的 11 种方法
  2. Type regedit and click OK to open Registry Editor .
  3. If you want to change user variables, navigate to this path: <strong>Computer\HKEY_CURRENT_USER\Environment</strong>在 Windows 3 上设置环境变量的 11 种方法
  4. For system variables, go to Go to the following path: <strong>Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment</strong>在 Windows 3 上设置环境变量的 11 种方法
  5. If you want to rename the variable name, right click and select "Rename".
  6. To edit the value data, double-click the variable, change the value data, and click OK. 在 Windows 3 上设置环境变量的 11 种方法
  7. Restart your computer to save changes.

3. Use Windows PowerShell

  1. Use the same steps above to open Windows PowerShell with administrator privileges.
  2. 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>在 Windows 3 上设置环境变量的 11 种方法
  3. 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>
  4. 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

在 Windows 3 上设置环境变量的 11 种方法

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>

在 Windows 3 上设置环境变量的 11 种方法

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!

Related labels:
source:yundongfang.com
Statement of this 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template