If you’re logged in as standard user in Windows, you may not be able to set user environment variables via the user interface. This is due to a bug in Windows 10 where clicking "Change my environment variables" link in the User Accounts Control Panel doesn’t work.
The following command-line is executed when you click the link, but it has no effect in Windows 10 v1511 and earlier, whether you run it as standard user or administrator.
Alternately, you can use the Setx command to set user environment variables.
Setting User Environment Variable
Open a Command Prompt window and type SETX /? to know the command usage. For example to set the JAVA_HOME variable, you would use:
SETX JAVA_HOME "C:\Program Files\Java\jdk1.6.0_02"
(Depending upon the version of the JDK installed, bitness of your OS, change the JDK folder path accordingly.)
This permanently sets the environment variable for your user account, and takes effect for future Command Prompt windows.
Delete a User Environment Variable
To clear the user variable, use this syntax/example:
SETX JAVA_HOME ""
This however, doesn’t delete the value from the following registry key:
So you need another command to clear it, although this is optional.
REG DELETE HKCU\Environment /V JAVA_HOME /F
This clears the JAVA_HOME user variable.
Note: Setx can also be used to set System Environment Variables using the "/M" switch, but you need to run it from elevated or administrator Command Prompt.
One small request: If you liked this post, please share this?One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
- Pin it!
- Share it to your favorite blog + Facebook, Reddit
- Tweet it!