Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Java on Windows machine

I have a Windows 10 x64 machine. I had Open JDK 10. My JAVA_HOME points to Open JDK 10 location. My Path variable has %JAVA_HOME%/bin; part.

Then I installed Java 8. https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Java installer changes Path.

 C:\Users\user>set Path 
 Path=C:\Program Files (x86)\Common Files\Oracle\Java\javapath;OTHER_STUFF_WITHOUT_JAVA

Now in command line java -version points to Java 8.

 C:\Users\user>java -version
 java version "1.8.0_202"
 Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
 Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)

But JAVA_HOME is still pointing to Open JDK 10.

C:\Users\user>set java_home
JAVA_HOME=C:\Java\jdk\jdk-10.0.2

My goal is to have Open JDK-10 as default Java.

This is not a duplicate Default Java Path on Windows Machines because there is no answer for me.

like image 596
Yan Khonski Avatar asked Mar 04 '23 15:03

Yan Khonski


2 Answers

(Post comment as the answer for readability)

The easiest way to have several JDK and be sure to point towards the good one, is to avoid using the java installers. You should just unzip the JDKs in a folder and then modify your JAVA_HOME and PATH accordingly. You could also have several JAVA_HOME like JAVA_HOME_8 and JAVA_HOME_10 pointing to their respective JDK folder and make your JAVA_HOME=%JAVA_HOME_10% so you can change easily.

like image 171
Julien Revault d'A... Avatar answered Mar 18 '23 19:03

Julien Revault d'A...


The easiest way i just found out is that the java 8 installer creates a new environment PATH entry:

C:\Program Files (x86)\Common Files\Oracle\Java\javapath

This will point to the latest installed JRE or JDK(i.e. the last in JDK or JRE) using the installer method.

So if your JAVA_HOME points to the JDK 10 OR JRE 10 just go to the Environment Variables and remove:

C:\Program Files (x86)\Common Files\Oracle\Java\javapath

From the PATH variable.

Then the values you used for JAVA_HOME will become effective.

This worked for me after installing java 8 and i had installed java 12

like image 40
briancollins081 Avatar answered Mar 18 '23 21:03

briancollins081