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 and provide step-by-step instructions to set and edit it on Windows 11.

Introduction to Environment Variables

Environment variables are named values that store configuration information for the operating system and applications. This dynamic data allows programs to find important resources, such as file paths, without needing to hardcode the information.

There are three types of environment variables, based on their scope. Among them, User environment variables and System environment variables are two primary types.

1. System Environment Variables

  • Scope: These variables affect the entire system and apply to all users and processes.
  • Permission: You must have administrator privileges to edit or create system-wide variables.
  • Purpose: These variables point to critical system resource locations, such as the Windows installation directory or program files.

For example, the %SystemRoot% variable always points to the directory where Windows is installed (e.g., C:\Windows).

2. User Environment Variables

  • Scope: These variables are specific to the currently logged-in user and affect only processes running under that user account.
  • Permission: Any user can create or modify their own user-level variables.
  • Purpose: They store user-specific settings, such as the location of the user profile or temporary files, or customized application settings.

For example, the %USERPROFILE% variable points to your specific user folder (e.g., C:\Users\username).

3. Process Environment Variables

  • Scope: These are temporary variables that apply only to the current Command Prompt or PowerShell session and its child processes.
  • Permission: A process can set and use these variables within its own session, but they are not saved system-wide.
  • Purpose: They are used to pass information to scripts and programs within a single session.

When you use them in Command Prompt, any variables created only exist until you close the Command Prompt window.

Set and Edit Environment Variables on Windows 11

How to set and edit environment variables on Windows 11? Here, we offer 3 approaches.

Method 1. Set and Edit Environment Variables via Setting

The Settings app is the most user-friendly way to manage environment variables, especially for beginners. It provides a graphical interface that avoids complex commands.

To set environment variables on Windows 11 via Settings, here are the steps:

Step 1. Search for “Edit environment variables” in the search bar and select the top result to open it.

Step 2. In the Environment Variables window, you can see two types of variables:

  • User variables
  • System variables
show two types of environment variables

Step 3. To create a new variable:

  1. Click New under the appropriate section (either User variables or System variables).
  2. Enter a Variable name without any spaces and Variable value, then click OK. You can click Browse Directory or Browse File to assign the variable to the desired location.
create a new environment variable

Step 4. To edit an existing variable:

  1. Select the variable from the list (e.g., Path) and click Edit.
  2. You can then add, edit, or delete entries. For the Path variable, you can add new folder locations.
  3. Click OK when you are finished.
edit an existing environment variable

Once you have made all your changes, click OK to save and exit. You may need to restart your PC for some system-wide changes to take effect.

Method 2. Set and Edit Environment Variables via Command Prompt

You can set and edit variables via Command Prompt. Here is the guide:

Step 1. Type cmd in the search bar, right-click it, and select Run as administrator to make system-wide changes.

Step 2. To view all current environment variables, type set and press Enter.

view all current environment variables in CMD

Step 3. To view a specific variable, type echo %VARIABLE_NAME% and press Enter. For example, echo %PATH%.

Step 4. To create a temporary variable, use the set command with this syntax and press Enter:

set VariableName=VariableValue

Tips:
Replace VariableName and VariableValue with the ones you want.

Step 5. To create a permanent variable, use the setx command:

setx VariableName Value /m

Method 3. Set and Edit Environment Variables via PowerShell

For more advanced, permanent changes via the command line, you can use PowerShell:

Step 1. Type PowerShell in the search bar. Right-click it and select Run as administrator.

Step 2. To list all environment variables, type [System.Environment]::GetEnvironmentVariables() and press Enter.

list all environment variables in PowerShell

Step 3. To view a specific variable, type $Env:VARIABLE_NAME and press Enter.

Step 4. To set a permanent user variable, type the following command and press Enter.

[System.Environment]::SetEnvironmentVariable(“MY_USER_VARIABLE”, “UserValue”, “User”)

Step 5. To create a permanent system variable, type the following command and press Enter.

[System.Environment]::SetEnvironmentVariable(“MY_MACHINE_VARIABLE”, “MachineValue”, “Machine”)

Troubleshooting Problems

When setting and editing environment variables on Windows, you may encounter the following problems:

#1. Environment variables not working

Spelling or syntax errors in environment variables can cause them not to work. Additionally, malware can interfere with the variables.

Therefore, you should make sure the environment variables’ names are correct and run a malware scan.

#2. Changes are not taking effect

You edited a variable, but the change didn’t take effect in Command Prompt, PowerShell, or other running applications. This happens because applications read and cache environment variables at startup and don’t automatically refresh them when you make changes.

You should close all open Command Prompt, PowerShell, or app windows, then reopen them.

#3. Broken system or apps after editing PATH

Accidentally deleting or modifying critical paths in PATH (e.g., C:\Windows\System32) can prevent Windows from finding system files.

You need to reopen the Environment Variables window, select PATH under System variables, and restore the missing path.

Bottom Line

How to set and edit environment variables on Windows 11? This post provides 3 methods for you. Pick one way according to your preference.

  • linkedin
  • reddit