Tech News Today
  • Hardware
    • Motherboards
    • CPUs
    • Graphic Cards
    • RAM
    • SSDs
    • Computer Cases
    • Monitors
    • Peripherals
    • Power Supply Unit
    • PC Builds
    • Computer Tips
  • Software
  • Operating System
    • Windows
    • Mac
    • Linux
  • Gaming
  • Mobile
  • Console
  • More
    • Internet
    • Networking
    • Security
    • Buyer’s Guide
    • Gadgets
    • Laptops
    • Reviews
    • How To
    • News
Facebook Twitter Instagram
Tech News Today
  • Hardware
    • Motherboards
    • CPUs
    • Graphic Cards
    • RAM
    • SSDs
    • Computer Cases
    • Monitors
    • Peripherals
    • Power Supply Unit
    • PC Builds
    • Computer Tips
  • Software
  • Operating System
    • Windows
    • Mac
    • Linux
  • Gaming
  • Mobile
  • Console
  • More
    • Internet
    • Networking
    • Security
    • Buyer’s Guide
    • Gadgets
    • Laptops
    • Reviews
    • How To
    • News
Tech News Today
Home»Windows»4 Ways How You Can Set Windows Environment Variables

4 Ways How You Can Set Windows Environment Variables

Bhishu AcharyaBy Bhishu AcharyaDecember 1, 2022
how to set windows environment variables

The environment variables are the key-value pairs that act as information containers for all the programs running on Windows. Simply put, they are the string variables an OS uses to manage all the apps and services.

Every application has its own set of environment variables, and it helps them determine where to install and store files. These variables contain names and values that help control the operational environment. Further, they have a significant effect and enable your computer’s active processes.

Without environment variables, you’ll need to inform your scripts every time to find the same path to a specific file. But if you set a dedicated variable, the information becomes available everywhere.

Whether you’re trying to feed data into a database or secure your configuration, the environment variables will help keep your code and data separated. Apart from that, they hold the following importance on Windows or any other OS:
  • Helps secure sensitive information
  • No need to worry about scheduled tasks and production mistakes
  • Provides better development experience
  • Easy navigation and configuration

Table of Contents

  • How to Set Windows Environment Variables
    • Using Windows GUI
    • In Registry Editor
    • In Command Prompt
    • In Windows Powershell

How to Set Windows Environment Variables

In Windows, the environment variables are categorized into two – User and System. While the former deals with user-defined settings (user profiles, files, etc.), the latter contains the values used by the operating system.

In this section, you will learn how to set Windows environment variables via the graphical user interface, command line interface (Command Prompt and Windows Powershell), and Registry Editor. So, without further delay, let’s get right into them in detail.

Using Windows GUI

Before setting up a Windows environment variable in the graphical user interface, you’ll need to navigate to the dedicated window: 

  1. Use Windows + I to launch Settings on your PC.
  2. Now, move to System > About.
    settings system about
  3. Here, expand Device Specifications and select Advanced system settings.
    device specifications advanced system settings
  4. This will open the Advanced tab in the System Properties dialogue box. Here, find and click on the Environment Variables button.
    environment variables button

Another way to open Environment Variables window is from the Control Panel utility. Kindly follow the below instructions on how you can do so:

  1. Press Windows + R and run the control Command to open Control Panel.
  2. Now, navigate to User Accounts.
    user accounts in control panel
  3. Again, choose User Accounts.
    user accounts
  4. Then, select Change my environment variables from the left pane.
    change my environment variables

Alternatively, you can directly launch it from the Run dialogue box by running the following command:
rundll32.exe sysdm.cpl,EditEnvironmentVariables
Also, this is possible from the Start menu, where you can search for “Edit the system environment variables” or “Edit environment variables for your account”.

Once the Environment Variables window pops up, go through the following guide to learn how to set the system environment variables on Windows 11:

  1. Press the New button under ‘User variables for [Your PC Name]’ to add a user variable.
    new button under user variables
    For adding a new system variable, use the New button under the System variables section.
    new button under system variables
  2. Next, enter a desired name in the Variable name field.
    edit variable name
  3. To add a path, press Browse Directory or Browse Field. Now, navigate to the path and tap the Open button. If you already know the correct location or want to add different data, you can directly enter it in the Variable value field.
  4. Finally, click Ok and check the list.
    set variable value

You can select the system or user variable if you want to change its name or value. Then, press the Edit button, and proceed with the same steps as above. Likewise, to delete an existing environment variable, select it and choose Delete.

In Registry Editor

Another way to set Windows environment variables is from the built-in Registry Editor tool. In fact, this is the precise location where all the user and system values are stored. Here’s a quick guide on how to do it the right way:

  1. Press Windows + R and run the following to open the utility:
    regedit.exe
  2. Now, copy and paste one of the below paths to view all the user or system variables on your computer:
    Computer\HKEY_CURRENT_USER\Environment (for user)
    registry editor go to user variable path
    HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment (for system)
  3. Next, go to Edit > New.
  4. Here, select any of the following value options – String, Binary, DWORD, QWORD, Multi-string, Expandable String. 
    registry editor new and select one value
  5. Move to the right pane and name the variable.
    set user variable in registry editor
  6. Then, double-click on it and enter an appropriate value in the Value data field.
  7. Hit Ok, which should set the Windows environment variable.
    edit user variable value

To edit the value, simply double-click the variable and change it to an appropriate one. Furthermore, you can right-click and pick Delete to remove the environment variable permanently.

In Command Prompt

If you prefer CLI (Command Line Interface) over GUI, the good news is that you can use simple commands to set Windows environment variables. Although you can create both user and system variables, there’s no individual section to display each of them.

Follow the below steps to view, set, edit, and delete Windows environment variables using Command Prompt:

  1. Firstly, press the Windows key to open the start menu. Then, search and launch Command Prompt.
  2. Use the below command to view all the environment variables (for both user and system):
    set
    set command in command prompt
  3. Next, you can use the below syntax to create a user variable of your own:
    setx variable_name “variable_value”
    For demonstration, we have used the following command to create a user variable named “Example” and set its value to “0”:
    setx Example “0”
    setx command in command prompt
    To create a system environment variable, you’ll need to use a slightly different syntax:
    setx /m variable_name “value”
    setx m command in command prompt
  4. Now, restart the Command Prompt and use the set command again to confirm that the environment variable is created successfully.
    set command to check if the environment variable is set
  5. To edit the value, you can use the same syntax used to create the environment variable. Here’s a simple example that should clear your doubt:
    setx Example “1” (for user)
    edit user environment variable in command prompt
    setx /m variable “1” (for system)
    edit system environment variable in command prompt
  6. Restart CMD and use the set command again to check the edited value.
    changed user environment variable
  7. In case you wish to delete an environment variable, you’ll need to use the following registry commands:
    REG delete HKCU\Environment /F /V variable_name (user)
    delete user environment variable
    REG delete "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /F /V variable_name (system)
    delete system environment variable

In Windows Powershell

Although Command Prompt is quite popular, most advanced Windows users prefer Powershell due to its extensibility. If you fall into this category, follow our guide to view, set, edit, and delete Windows environment variables via Powershell:

  1. Press Windows + X and select Windows Terminal to enter the Powershell interface.
    quick link menu windows terminal
  2. Here, use the below cmdlets to view the present environment variables on your PC:
    Get-ChildItem Env: (view all environment variables)
    get childitem env
    [Environment]::GetEnvironmentVariables("User") (view the user variables)
    view user variables
    [Environment]::GetEnvironmentVariables("Machine") (view the system variables)
    get system environment variables
  3. To add a new variable, kindly use the appropriate syntax from below:
    [Environment]::SetEnvironmentVariable("variable_name","value","User") (for user)
    powershell add user variable
    [Environment]::SetEnvironmentVariable("Ex","0","Machine") (for system)
    powershell add system variable
  4. Now, simply use the view cmdlet to confirm that the variable was created.
    check if variable is added in powershell
  5. If you’re unsatisfied with the value, you can quickly change it using the same commands used for creating the environment variable.
  6. To delete the Windows environment variable, kindly have a look at the below command lines:
    [Environment]::SetEnvironmentVariable("variable_name", $null ,"User") (user)
    delete user environment variable in powershell
    [Environment]::SetEnvironmentVariable("variable_name", $null ,"Machine") (system)
    delete system environment variable in powershell
how-to
Bhishu Acharya
  • Tumblr
  • LinkedIn

Bhishu Acharya is a technical content writer at TechNewsToday. He specializes in monitors, laptops, storage devices, and other peripherals. Apart from computer hardware, you can also find his how-to and troubleshooting articles on Windows, internet, security, and networking. Ever since getting his hands on a personal computer, Bhishu started exploring its internal components at just 10. His growing curiosity led him to undertake the Computer Science & Information Technology degree and is just a year away from graduation. While balancing his study and work life for over four years, he has harnessed different sets of technical skills. With his expertise, he is now dedicated to helping netizens looking for hardware and software-related fixes. Today, Bhishu’s proficiency extends beyond computer hardware. In his spare time, he enjoys coding and learning new programming languages. You can contact him at bhishu@technewstoday.com

Related Posts

how to delete win backup files

How to Delete Backup Files on Windows

January 29, 2023
how to reset password on hp laptop

How to Reset Password on HP Laptop

January 29, 2023
Reset BIOS password

4 Ways to Reset BIOS Password

January 28, 2023
how to make windows 11 look like windows 10

How to Make Windows 11 Look Like Windows 10

January 25, 2023
how to find hidden folder in laptop

How to Find Hidden Folder in Laptop

January 24, 2023
mouse not showing in chrome

Mouse Not Showing in Chrome? Here’s How to Fix It

January 25, 2023
Add A Comment

Leave A Reply Cancel Reply

Latest Posts
how long does a cmos battery last

How Long Does a CMOS Battery Last

January 25, 2023
thunderbolt vs usb c

Thunderbolt Vs USB C: What’s the Difference

January 25, 2023
how to find hidden folder in laptop

How to Find Hidden Folder in Laptop

January 24, 2023
You may also like
how-to-connect-headphones-to-tv

5 Ways to Connect Headphones to TV

January 29, 2023
connect-airpods-to-samsung-tv

How to Connect AirPods to Samsung TV? (Step-by-Step Guide)

January 29, 2023
AIO Pump Not Working

AIO Pump Not Working? Here’s How to Fix It

January 29, 2023
Recommended
Cookie Clicker Garden Guide

Cookie Clicker Garden Guide to Unlocking Every Seed

September 26, 2021
monitor no signal

Computer Turns On But Monitor Says No Signal (9 Ways To Fix)

November 10, 2022
Facebook Twitter Pinterest
  • Home
  • About Us
  • Our Team
  • Editorial Guidelines
  • Privacy Policy
  • Affiliate Disclosure
© 2023 TechNewsToday.

Type above and press Enter to search. Press Esc to cancel.