22 Responses to “How to edit, clear, and delete environment variables in Windows”

  • codeninja95 says:

    Can anyone please tell how to remove a path from path variable using command ?

  • Martha says:

    For system variable settings:

    REG delete “HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment” /F /V “variable to delete”

    If it is in the user environment:
    REG delete “HKCUEnvironment” /F /V “variable to delete”

  • RandomUser says:

    You can delete environment variables from the command line via:

    REG delete HKCUEnvironment /F /V VAR_NAME

  • Martin says:

    this seems to do it:
    set var=

  • Vishnu says:

    You can clear an environment variable on the command line by using:

    set VARIABLE=

    (Nothing after the equal sign)

  • Steve S, says:

    Delete env variable from the command line

    SET Variable=

  • Is there a solution to delete variable says:

    Delete From Current Process

    Obviously, everyone knows that you just do this to delete an environment variable from your current process:

    set FOO=

    Persistent Delete

    There are two sets of environment variables, system-wide and user.

    Delete User Environment Variable:

    reg delete “HKCUEnvironment” /v FOO /f

    Delete System-Wide Environment Variable:

    REG delete “HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment” /F /V FOO

    https://stackoverflow.com/questions/13222724/command-line-to-remove-an-environment-variable-from-the-os-level-configuration

  • Stef says:

    Hello,

    If you can use PowerShell, you can define a machine environment variable with:
    [Environment]::SetEnvironmentVariable(“MYVAR”, “MYVALUE”, [EnvironmentVariableTarget]::Machine)
    and delete it with:
    [Environment]::SetEnvironmentVariable(“MYVAR”, $null, [EnvironmentVariableTarget]::Machine)

    Rgds
    Stef

  • Ryg says:

    To delete a user variable using command line, you can do it following way :
    reg delete HKCUEnvironment /v FOOBAR /f

  • Kyle_IT says:

    Enviroment Variables are stored in the Registry keys:
    HKEY_CURRENT_USEREnvironment (User)
    Or
    HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession (System)
    You can delete enviroment variables by deleting the keys themselves.

    • Anonymous says:

      Good tip. Thanks!

    • Tom says:

      I want remove variable only temporarily for one command. How to do that? I don’t want remove permanently. I tried set envvar= && command using command chaining but it seems bug in windows, and set envvar= doesn’t clear variable as without chaining do.

  • Jeremy Flowers says:

    To remove an environment variable from the command line use SET envvarname=

  • Lee says:

    To remove an environment variable using the command line simply set it to an empty value e.g. to remove for just this session you could execute “SET VariableName=” without the double quotes

  • TVR says:

    You can remove environment variables on the command line by typing:

    SET var=

    (not: SET var=””)

  • Gourav Dhol says:

    Command to Delete User environment variable (Windows). Here “eclipse” is variable name

    reg delete “HKCUEnvironment” /v eclipse /f

  • Bryan says:

    to delete and environment variable from the command line just set the variable to blank.

  • remove from command line says:

    SETX FOOBAR “” & REG delete HKCUEnvironment /F /V FOOBAR

  • sferrell615 says:

    to remove an environment variable just enter
    set =
    e.g. set __COMPAT_LAYER=

    • Ciprian Adrian Rusen says:

      The variable remains but, it has an empty value.

    • scififellow says:

      Works for me in cmdr prompt:

      λ set david=hello

      λ set | grep david
      david=hello

      C:downloadapache-tomcat-8.5.29_2
      λ echo %david%
      hello

      λ set david=

      λ set | grep david // no output here

Leave a Reply