Logo

How to Set Environment Variables in Windows

Try this guide with our instant dedicated server for as low as 40 Euros

Environment Variable

Have you ever wondered how your computer locates programs when you give a command or click a file in a folder?

Windows uses environment variables to manage these settings.

Environment variables are key-value pairs that Windows and applications use to store information that affects program operations and user experience. They are crucial in configuring system behavior options, from setting the system’s path for executable files to defining user-specific preferences.

A good example of using system environment variables in Windows is to store the default language or the home directory’s location.

By learning how to set, view, and unset these variables, you gain more control over how your applications and system operate, leading to a more efficient and customized experience.

This article will walk you through the different methods of setting, viewing, and unsetting environment variables in Windows. By the end of this tutorial, you’ll clearly understand how to manage environment variables to customize your Windows environment according to your needs.

Let’s start with a short discussion on environment variables in Windows.

Table of Contents

  1. Do You Really Need to Know Environment Variables?
    1. Prerequisites
  2. How to View the Current Environment Variables in Windows
    1. Method #1: List All Environment Variables
    2. Method #2: Check a Particular Environment Variable
  3. How to Set Environment Variables in Windows
    1. Method #1: Set Environment Variables Through the GUI
    2. Method #2: Use the Command Prompt to Set Environment Variables
  4. How to Unset the Current Environment Variables in Windows
    1. Method #1: Unset Environment Variables Via the GUI
    2. Method #2: Unset Environment Variables Via the Registry
  5. Conclusion
  6. FAQs

Do You Really Need to Know Environment Variables?

In short — yes!

Understanding and managing environment variables is essential because they ensure that the software on your computer runs in a way tailored to your specific needs.

Let’s consider an example. When you install a new program, it might add its home directory to the PATH environment variable, allowing you to run it from anywhere on the system without specifying the full directory path.

Similarly, developers often use environment variables to set development and production environments, ensuring software behaves as expected.

Let’s start with how to view the current environment variables in Windows.

Prerequisites

Before viewing, setting, and unsetting environment variables, make sure you have the following in place:

  • A Windows 10 system
  • A user account with Administrator privileges

How to View the Current Environment Variables in Windows

Windows offers several ways of viewing the current environment variables. These methods use the Windows PowerShell and Command Prompt.

Let’s look at the two ways of viewing Windows environment variables.

Method #1: List All Environment Variables

You can use the set command in the Command Prompt to get a list of all environment variables in Windows.

> set

How to View the Current Environment Variables in Windows

If you prefer Windows PowerShell, run the following command to list every environment variable:

> Get - ChildItem Env:

Get - ChildItem Env

As you can see, the command lists all available environment variables and their values.

Method #2: Check a Particular Environment Variable

If you are interested in a specific environment variable, we recommend the echo command in Windows PowerShell or Command Prompt.

Use the following command syntax in the Command Prompt to print the value of an environment variable:

> echo %[PATH]%

Method #2 Check a Particular Environment Variable

Remember to replace PATH with the name of the environment variable you want to check. For instance, in the following screenshot, we used the echo %OS% to print the value of the environment variable.

Alternatively, use the following command syntax in Windows PowerShell:

> echo $Env:[PATH]

echo $Env[PATH]

How to Set Environment Variables in Windows

After viewing environment variables, let’s see how you can set them in Windows. We will introduce the following two methods.

Method #1: Set Environment Variables Through the GUI

Windows GUI offers a simple way of setting environment variables. Here are the steps of the process:

  1. Press Windows + R to launch the Windows Run prompt.
  1. Enter sysdm.cpl and press Enter to launch the System Properties window.

Enter sysdm.cpl and press Enter to launch the System Properties window.

  1. Click the Advanced tab (1) to access the Environment Variables button (2).

Click the Advanced tab (1) to access the Environment Variables button (2)

  1. You will see two sections in the Environment Variables window, one for the user-level environment variables and the other for the system environment variables. To add a new variable, click the New… button in the appropriate section.

To add a new variable, click the New… button in the appropriate section.

  1. Type the name and the value of the environment variable in the New User Variable prompt and then click OK.

Type the name and the value of the environment variable in the New User Variable prompt and then click OK.

Method #2: Use the Command Prompt to Set Environment Variables

To create a new user-specific environment variable, use the setx command syntax in the Command Prompt:

> setx [variable_name] "[variable_value]"

You need to make the following modifications to the syntax:

  • [variable_name]: The name of the environment variable.
  • [variable_value]: The value of the environment variable.

For instance, consider the following example command:

> setx Test_variable "Variable value"

Method #2 Use the Command Prompt to Set Environment Variables

You can add a system-wide environment variable by adding the /M flag to the setx command. Here’s the command syntax:

> setx [variable_name] "[variable_value]" /M

setx [variable_name] [variable_value] M

How to Unset the Current Environment Variables in Windows

In Windows, you can unset environment variables in two different ways:

Method #1: Unset Environment Variables Via the GUI

To access and unset an environment variable using the GUI in Windows, go to the section on setting environment variables via the GUI and follow these instructions:

  1. Find the variable you need to unset in the relevant section.
  2. Click it to highlight the variable.
  3. To reset it, click the Delete button.

To reset it, click the Delete button.

Method #2: Unset Environment Variables Via the Registry

The Windows Registry is the central database in Windows, storing configurations for the OS, software, and hardware. You can easily unset or delete environment variables in Windows by editing the relevant entry in the Registry.

Warning: Editing the Windows Registry can lead to system instability if not done correctly. Ensure you have a backup before making any changes.

Here are the steps you can follow to unset an environment variable in Windows:

1. Open the Registry Editor:

  • Press Win + R to open the Run dialog.
  • Type regedit and press Enter to open the Registry Editor.

Type regedit and press Enter to open the Registry Editor.

2. Navigate to Environment Variables:

Navigate to HKEY_CURRENT_USER\Environment for user-specific variables or HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment for system-wide variables.

Navigate to Environment Variables

  1. Identify the variable you want to unset.
  2. Right-click on the variable and select Delete.
  3. Confirm the deletion when prompted.
  4. Close the Registry Editor.

After closing it, the environment variable is unset successfully.

Conclusion

Setting, unsetting, or modifying environment variables with the right approach can effectively tailor your system to specific needs. It involves various methods, from using the GUI to editing the Registry. Whether through a user-friendly interface or more advanced settings, always exercise caution to ensure system stability.

In this guide, we’ve walked you through setting environment variables step-by-step, allowing you to customize your Windows environment to fit particular setups and preferences. With this knowledge, you can optimize your Windows operating system by defining system-wide settings, configuring application behaviors, and modifying path environment variables to improve your Windows computing experience overall and speed up your workflow.

RedSwitches offers the best dedicated server pricing and delivers instant dedicated servers, usually on the same day the order gets approved. Whether you need a dedicated server, a traffic-friendly 10Gbps dedicated server, or a powerful bare metal server, we are your trusted hosting partner.

FAQs

Q. What are environment variables in Windows?

Environment variables in Windows are dynamic values that store configuration settings, system paths, and other crucial information utilized by the operating system and applications.

Q. Why would I need to set environment variables?

Setting environment variables allows you to customize system behavior, define path variables for executable files, and configure specific application settings, providing flexibility and control over your Windows environment.

Q. In Windows, is it possible to set environment variables for particular users?

It is possible to set environment variables for the system and the current user simultaneously. System-wide variables impact all users on the Windows computer, whereas user-specific variables only apply to the logged-in user.

Q. How can I permanently set environment variables in Windows?

To set environment variables permanently, follow the steps provided below:

  • Right-click on “This PC” or “Computer.”
  • Select “Properties.”
  • Click on “Advanced system settings.”
  • In the “System Properties” window, click “Environment Variables” and add or edit variables in the user or system section.

Q. Can I use the Command Prompt to set environment variables?

Yes, you can use the set command in the Command Prompt to set environment variables temporarily. However, changes made this way are not persistent across a single current session.

Q. What’s the difference between user and system environment variables?

System environment variables impact all users and the entire Windows system, whereas user environment variables are unique to the active user.

Q. Is it possible to view all existing environment variables in Windows?

Yes, you can use the set command in the Command Prompt to view all existing environment variables. Just type this command and press Enter.

Q. Can I set environment variables for specific applications only?

Environment variables are typically global, affecting the entire system or user. However, some applications may allow you to set variables specific to their configuration.

Q. Do I need administrative privileges to set environment variables?

Yes, to set user-specific and system-wide environment variables, administrative privileges are required.

Q. How do I troubleshoot if environment variables are not working as expected?

Double-check the variable names and values for typos. Ensure that you’ve applied the changes correctly, and if issues persist, consult Windows documentation or community forums for additional support

Try this guide with our instant dedicated server for as low as 40 Euros