Question

I have both Java 6 and Java 7 on my computer (Windows7) but running command:

java -version 

I got the following:

java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)

How can I set the java 7 as the default?


Edit: I've already updated the PATH, and in fact when I do

javac -version

...it gives me 1.7.0_11, but java -version still gives me the above.

Was it helpful?

Solution

  1. Go to Control Panel > System and Security > System > Advanced System Settings

  2. Click the Environment Variables... button

  3. In the System variables box at the bottom, update the Path variable so that it includes the Java7 bin directory rather than the Java6 one

  4. If you see a JAVA_HOME variable listed there, update it as well (if you don't see one, that's fine)

Once you've done that, you'll have to close and reopen any command prompts you have open.


Re your note below (which I've edited into the question):

Actually I already have updated it. So, the java 6 path does not exist in my environmental variables. It is strange, if I check the: javac -version it returns: javac 1.7.0_11 but not for java -version.

Look at the Path again, I suspect you'll find that there are separate entries for the JDK's bin and the JRE's bin. That's normal. You probably updated the JDK's entry but not the JRE's.

Another thing to do is to find out where that java.exe file is located. You can do that like this:

where java.exe

That will search your path and show you where it finds the java.exe file. I was very surprised to find on a fresh Java8 install just now that it was in the C:\Windows\System32 directory, so that may be what's going on on your system.

You may find this question and its answers useful, particularly the STATIC=1 JRE installation option. That information appears to still relate to Java 7 at least.

OTHER TIPS

look into C:\Windows\System32 you will find java.exe. The C:\Windows\System32 is before what you set.So put your java path before C:\Windows\System32 like: %JAVA_HOME%\bin;...;%SystemRoot%\system32;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top