Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including
Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
The best answers are voted up and rise to the top
13 years, 5 months ago
I want to set an environment variable from the command prompt and then be able to access it globally (for instance, I should see it by going to System -> Environment Variables).
When I use the set command, it isn't accessible in a new cmd session.
Dec 6, 2009 at 21:52
3,580 5 5 gold badges 21 21 silver badges 18 18 bronze badges
To make the environment variable accessible globally you need to set it in the registry. As you've realised by just using:
you are just setting it in the current process space.
this page you can use the command:
setx NEWVAR SOMETHING
setx is built into Windows 7, but for older versions may only be available if you install the
Windows Resource Kit
37.1k 36 36 gold badges 139 139 silver badges 177 177 bronze badges
Dec 6, 2009 at 21:58
41.2k 17 17 gold badges 98 98 silver badges 152 152 bronze badges
We can also use "setx var variable /M" to set the var to system environment variable level instead of user level.
Note: This command should be run as administrator.
40.1k 42 42 gold badges 84 84 silver badges 127 127 bronze badges
Aug 26, 2014 at 10:37
Minh Chau Minh Chau
481 4 4 silver badges 2 2 bronze badges
You can use
setx env var [/M] as mentioned above.
If it doesn't take effect you can use
refreshenv to refresh environment variables. You don't have to restart your computer, explorer.exe or your command prompt to do that.
Edit: apparantly refreshenv doesn't come naturally with Windows, so here's the source:
Save as RefreshEnv.cmd and place it in a folder that's included in your PATH environment variables
Nov 13, 2018 at 19:42
211 2 2 silver badges 5 5 bronze badges
System variables can be set through CMD and registry
reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PATH
All the commonly used CMD codes and system variables are given here:
Set Windows system environment variables using CMD.
Open CMD and type
You will get all the values of system variable.
set java to know the path details of java installed on your window OS.
Mar 9, 2017 at 5:06
I want to add that if you are using the /s parameter with setx in order to set environment variables on a remote computer, the "Remote Registry" service needs to be running on the target machine or else you will receive a "ERROR: The specified operation could not be completed."
(I have asked Microsoft to update their
TechNet article on setx to include this information.)
May 18, 2017 at 19:35
Tim Bailen Tim Bailen
91 1 1 silver badge 3 3 bronze badges
. Earn 10 reputation (not counting the Highly active question association bonus) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our
Accept all cookies
Necessary cookies only