Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is a very basic question, but I can't find an answer. 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.

set NEWVAR=SOMETHING
echo %NEWVAR%

Related questions:

share|improve this question
up vote 91 down vote accepted

To make the environment variable accessible globally you need to set it in the registry. As you've realised by just using:

set NEWVAR=SOMETHING

you are just setting it in the current process space.

According to this page you can use the setx 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

share|improve this answer
7  
It turns out that setx is also built into windows 7. – Shane Mar 25 '10 at 11:30
    
Note that you need to specify quota, for example : setx JAVA_HOME "C:\Program Files\Java\jdk1.7.0_45" will work. But setx JAVA_HOME C:\Program Files\Java\jdk1.7.0_45 will give you syntax errors – MD. Mohiuddin Ahmed Oct 22 '15 at 9:00
1  
@MD.MohiuddinAhmed That's because there are spaces in the path. – ChrisF Oct 22 '15 at 9:15
    
Oops! I didn't notice that! ... Still good point to note :) Thanks @ChrisF ! – MD. Mohiuddin Ahmed Oct 22 '15 at 15:14

We can also use "setx var variable /M" to set the var to system environment variable level instead of user level

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.