Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

In Windows 7, when I start the Command prompt, is there any command to display the contents of an environment variable (such as the JAVA_HOME or PATH variables)?

I have tried with echo $PATH, echo PATH and $PATH but none of these work.

share|improve this question
-1, as the most up voted and community-faq tagged topic in the environment-variables tag contains the answer, this questions does not show any research effort. – Daniel Beck Oct 1 '11 at 10:39
@Daniel: I know how to set environment variables in Windows, I simply open "System properties" > "Advanced" and "Environment Variables". So I don't expect the answer to my question in a question titled with "How do I set PATH and other environment variables?", because I know that! I'm not asking about how to set them. – Jonas Oct 1 '11 at 12:00
In a way you're right - as one of the authors in the other topic, I haven't actually noticed the exact wording for a long time. I edited that topic to reflect its actual contents. I'm not going to change the vote though, both because I can't, and because I stand by my assessment that this topic shows no research effort. – Daniel Beck Oct 1 '11 at 12:14
up vote 265 down vote accepted

In Windows Command-Prompt the syntax is echo %PATH%

To get a list of all environment variables enter the command set

To send those variables to a text file enter the command set > filename.txt

share|improve this answer
Why is this value different from what I've specified in computer properties? – Johnny_D Sep 19 '13 at 9:45
@Johnny_D It is likely that either you have a user scoped variable or you have a session scoped variable (using the set command inside a command prompt does not keep the change after you close the console window) that is overriding it. – Scott Chamberlain Dec 7 '13 at 9:09

To complement the previous answer, if you're using Powershell echo %PATH% would not work. You need to use the following command instead: echo $Env:PATH

share|improve this answer
Also in PS: ls env: for listing all environment variables – George Mauer Aug 8 '15 at 16:24

As an additional bit of information: While SET works with global or system variables, sometimes you want to write and read User variables, and this is done with the SETX command. SETX is included in the base installs of Windows beginning with Vista, but was also available in Windows XP by installing the Resource Pack.

One difference about SETX though is that you cannot read the variable out in the same command window you wrote it in. You have to write the SETX command in one Command or Powershell window, and then open a new window to read it using ECHO.

SETX can also write global or system variables.

To Set a user variable using SETX:

setx variable value

To set a global or system variable using SETX:

setx /m variable value

To read a user or global variable:

Remember, you must open a new Command or Powershell window to read this variable.

echo %variable%
share|improve this answer

From SET /?:


would display all variables that begin with the letter 'P'

So for example if you want to find value of environment variable %PATH%, you can just type set path.

This is 3 characters shorter than echo %PATH%, but note that it also lists other variables starting with "path" (e.g. PATHEXT).

share|improve this answer

For me the solution was a bit diferent, it won't recognize the system environment variable JAVA_HOME, i had to set JAVA_HOME as User environment variable, so that i can use %JAVA_HOME% in system environment variable setting up.

Resuming, I had to:

-add a user environment variable: %JAVA_HOME% as:

"C:\Program Files\Java\jdk1.8.0_25";

-add to %PATH% system environment variable:


-latter on command line:

echo %JAVA_HOME%, and it retrieved the correct path (before it wasn't recognizing); echo %PATH%, and it retrieved the "C:\Program Files\Java\jdk1.8.0_25\bin" composed with %JAVA_HOME% user variable;

And it worked for me, hope it helps!!

share|improve this answer

You must log in to answer this question.

protected by Community Mar 20 '15 at 18:59

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged .