How to change, clear or delete environment variables in Windows
Programmers, system administrators and power users may need to work at some point with environment variables. Some may want to delete an environment variable; others will want to change its value, and so on. This guide shares how to change, clear and remove any environment variable, in Windows 10, Windows 7 and Windows 8.1:
Open the Environment Variables window
To make many of the edits shown in this article, you first need to open the Environment Variables window. This guide explains how to open this window and shows you the basics about working with environment variables: Simple questions: What are environment variables in Windows?
If you want to skip reading it, one path that works the same in all versions of Windows is to open the Control Panel and go to “System and Security - > System.” There, click or tap the “Advanced system settings” link on the left. The System Properties window is opened. There click the Environment Variables button.
For some of the steps shown in this article, you also need to open the Command Prompt (cmd.exe) as administrator. So do that too before moving forward.
How to change the value of an environment variable in Windows
If you want to change the value of an existing environment variable, first select it in the Environment Variables window. Then, click or tap Edit.
You are shown a window where you can edit both the name and the value of the variable. Make the modifications you desire and press OK. Then, press OK one more time in the Environment Variables window.
You can edit the value of an existing environment variable (but not the name), from the Command Prompt too. The command you have to enter is setx variable_name “value”.
For example, we typed setx TEST “C:\” and we created a user variable named TEST with the value C:\. One aspect to note is that the setx command rewrites the existing value with the one you type. Therefore, if you use this command multiple times on the same variable, the variable will keep the last value that you typed.
If you want a variable to have multiple paths in its value, you must write them all, separated by a semicolon, without spaces, like in the screenshot below.
How to clear the value of an environment variable in Windows
If you want to remove the value of an environment variable (while keeping its name), you cannot do that with the mouse and keyboard from the Environment Variables window. If you select a variable and press Edit, you can delete the value but you cannot press OK, as this button gets grayed out. Therefore you cannot save your changes.
Your only chance to clear the value of an environment variable is to use the Command Prompt. Type the command setx variable_name “”. For example, we typed setx TEST “” and this environment variable now had an empty value.
Next, let’s see how to remove an environment variable.
How to delete an environment variable in Windows
If you no longer want to use a particular environment variable, select it in the Environment Variables window. Then, press Delete. Windows does not ask for any confirmation of this action. Therefore, if you have changed your mind, you must press Cancel, so that the removal is not applied. If you want the deletion to go ahead, also press OK.
Do you know how to delete an environment variable from the Command Prompt?
Unfortunately, we did not find a method to remove environment variables from the Command Prompt. If you know one, do not hesitate to share it in a comment below. We promise to update this article based on your comment(s).