添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
  • Colocation
    Overview
  • Data Center as a Service
    Solutions for Digital Transformation
  • Hardware as a Service
    Flexible Hardware Leasing
  • Meet-Me Room
    The Interconnectivity Hub
  • Schedule a Tour
    Guided Virtual Data Center Tour
  • Data Center Locations
    Global Data Center Footprint
  • Platform
    Overview
  • Rancher Deployment
    One-Click Kubernetes Deployment
  • Intel Xeon E-2300
    Entry-Level Servers
  • 4th Gen Intel Xeon Scalable CPUs
    Boost Data-Intensive Workloads
  • Alliances
    Technology Partnerships
  • Object Storage
    S3-Compatible Storage Solution
  • Dedicated Servers
    Overview
  • FlexServers
    Vertical CPU Scaling
  • Intel Xeon-E Servers
    Intel Xeon 2200 Microarchitecture
  • GPU Servers
    Servers with NVIDIA Tesla GPUs
  • Dedicated Servers vs. BMC
    Compare Popular Platforms
  • Promotions
    See Available Discounts
  • Buy Now
    See All Servers
  • Managed Private Cloud (MPC)
    Highly Customizable Cloud
  • Data Security Cloud
    Secure-By-Design Cloud
  • Hybrid Cloud
    Multi-Platform Environment
  • Edge Computing
    Globally Distributed Servers
  • Object Storage
    S3 API Compatible Storage Service
  • Bare Metal Cloud
    API-Driven Dedicated Servers
  • Alternative Cloud Provider
    Overcome Public Cloud Limitations
  • Backup Solutions
    Veeam-Powered Services
  • Disaster Recovery
    VMware, Veeam, Zerto
  • Veeam Cloud Connect
    Backup and Replication
  • Managed Backup for Microsoft 365
    Veeam-Powered Service
  • Data Security Cloud
    Secure-by-Design Cloud
  • Encryption Management Platform (EMP)
    Cryptographic Key Management
  • Confidential Computing
    Data-in-Use Encryption
  • Ransomware Protection
    Data Protection and Availability
  • DDoS Protection
    Network Security Features
  • Network Overview
    Global Network Footprint
  • Network Locations
    U.S., Europe, APAC, LATAM
  • Speed Test
    Download Speed Test
  • Blog
    IT Tips and Tricks
  • Glossary
    IT Terms and Definitions
  • Resource Library
    Knowledge Resources
  • Events
    Let's Meet!
  • Newsroom
    Media Library
  • Developers
    Development Resources Portal
  • APIs
    Access Our Public APIs
  • GitHub
    Public Code Repositories
  • How to Set Environment Variable in Windows

    January 26, 2021

    Introduction

    Environment variables are key-value pairs a system uses to set up a software environment. The environment variables also play a crucial role in certain installations, such as installing Java on your PC or Raspberry Pi .

    In this tutorial, we will cover different ways you can set, list, and unset environment variables in Windows 10.

    Prerequisites

  • A system running Windows 10
  • User account with admin privileges
  • Access to the Command Prompt or Windows PowerShell
  • Check Current Environment Variables

    The method for checking current environment variables depends on whether you are using the Command Prompt or Windows PowerShell:

    List All Environment Variables

    In the Command Prompt, use the following command to list all environment variables:

    If you are using Windows PowerShell, list all the environment variables with:

    Get-ChildItem Env:

    Check A Specific Environment Variable

    Both the Command Prompt and PowerShell use the echo command to list specific environment variables.

    The Command prompt uses the following syntax:

    echo %[variable_name]%

    In Windows PowerShell, use:

    echo $Env:[variable_name]

    Here, [variable_name] is the name of the environment variable you want to check.

    Set Environment Variable in Windows via GUI

    Follow the steps to set environment variables using the Windows GUI:

    1. Press Windows + R to open the Windows Run prompt.

    2. Type in sysdm.cpl and click OK .

    3. Open the Advanced tab and click on the Environment Variables button in the System Properties window.

    4. The Environment Variables window is divided into two sections. The sections display user-specific and system-wide environment variables. To add a variable, click the New… button under the appropriate section.

    5. Enter the variable name and value in the New User Variable prompt and click OK .

    Set Environment Variable in Windows via Command Prompt

    Use the setx command to set a new user-specific environment variable via the Command Prompt:

    setx [variable_name] "[variable_value]"

    Where:

  • [variable_name] : The name of the environment variable you want to set.
  • [variable_value] : The value you want to assign to the new environment variable.
  • For instance:

    setx Test_variable "Variable value"

    To add a system-wide environment variable, open the Command Prompt as administrator and use:

    setx [variable_name] "[variable_value]" /M

    Unset Environment Variables

    There are two ways to unset environment variables in Windows:

    Unset Environment Variables in Windows via GUI

    To unset an environment variable using the GUI, follow the steps in the section on setting environment variables via GUI to reach the Environment Variables window.

    In this window:

    1. Locate the variable you want to unset in the appropriate section.

    2. Click the variable to highlight it.

    3. Click the Delete button to unset it.

    Unset Environment Variables in Windows via Registry

    When you add an environment variable in Windows, the key-value pair is saved in the registry. The default registry folders for environment variables are:

  • user-specific variables: HKEY_CURRENT_USEREnvironment
  • system-wide variables: HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment
  • Using the reg command allows you to review and unset environment variables directly in the registry.

    Note: The reg command works the same in the Command Prompt and Windows PowerShell.

    Use the following command to list all user-specific environment variables:

    reg query HKEY_CURRENT_USEREnvironment

    List all the system environment variables with:

    reg query "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment"

    If you want to list a specific variable, use:

    reg query HKEY_CURRENT_USEREnvironment /v [variable_name]
    reg query "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment" /v [variable_name]

    Where:

  • /v : Declares the intent to list a specific variable.
  • [variable_name] : The name of the environment variable you want to list.
  • Use the following command to unset an environment variable in the registry:

    reg delete HKEY_CURRENT_USEREnvironment /v [variable_name] /f
    reg delete "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment" /v [variable_name] /f

    Note: The /f parameter is used to confirm the reg delete command. Without it, entering the command triggers the Delete the registry value EXAMPLE (Yes/No)? prompt.

    Run the setx command again to propagate the environment variables and confirm the changes to the registry.

    Note: If you don’t have any other variables to add with the setx command, set a throwaway variable. For example:

    setx [variable_name] trash

    Conclusion

    After following this guide, you should know how to set user-specific and system-wide environment variables in Windows 10.

    Looking for this tutorial for a different OS? Check out our guides on How to Set Environment Variables in Linux , How to Set Environment Variables in ZSH , and How to Set Environment Variables in MacOS .

    Was this article helpful?
    Yes No
    Aleksandar Kovačević
    With a background in both design and writing, Aleksandar Kovacevic aims to bring a fresh perspective to writing for IT, making complicated concepts easy to understand and approach.
    Next you should read
    SysAdmin How to Set Environment Variables in MacOS
    January 18, 2021
    Environment variables store values that help build the system environment and run processes. In this...
    Read more SysAdmin How to Set Environment Variables in Linux
    December 17, 2020
    Environment variables play a significant role in setting up the system and shell configuration at the...
    Read more DevOps and Development SysAdmin How to Install Java on Raspberry Pi
    April 25, 2020
    This article guides you through the Java installation process on Raspberry Pi. You will also learn how to set...
    Read more DevOps and Development SysAdmin How to Install Java 11 & 12 on CentOS 7
    June 23, 2019
    As a highly popular programming language, Java is used for developing anything from lightweight mobile to...
    Read more