1

today I was looking after my Java Version and I got very confused. I found three different ones:

  • If I look in Webstorm it uses: 1.6.0_65
  • If I make java -version I get: 1.7.0_45
  • If I look in the system settings I get: 1.8.0_45

What can I do to just have system wide ONE Java version which will be the version which I update via my system settings: 1.8.0_45?

1

2 Answers 2

1

In some terms this is misunderstanding, but I hope it gets clearer soon:

The Apple packaged JRE/JDK is always installed in /System/Library/Frameworks/JavaVM.framework/Versions/Current, where "Current" is a link pointing to the actual version. Therefore, you can have multiple versions installed and use multiple versions in Xcode or other IDE.

Oracle and its installers install their JDK/JRE in /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home for the webbrowser plugin and the full JRE/JDK into /Library/Java/JavaVirtualMachines/.

And additionally, software packages can come with their own JDK/JRE package. For instance, HP Peregrine Service Center does that.

So when each application comes with its own JDK/JRE, you need to tell in some configuration which one to use. In general, for all shell driven applications there is one environment variable you usually set for this and it's called JAVA_HOME. Software like tomcat respect this.

Take a closer look at this:

endor-2:~ garex$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    1.8.0_45, x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
    1.7.0_71, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home

With the following java_home command you permanently switch over to Java 1.8 64 bit:

endor-2:~ garex$ java -fullversion
java full version "1.7.0_71-b14"
endor-2:~ garex$ /usr/libexec/java_home -v 1.8 -d64
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
endor-2:~ garex$ which java
/usr/bin/java
endor-2:~ garex$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

But remember: you could do that, but do not expect certain software to follow that. In my case I installed JRE and JDK.

By using the java_home command in your calling script you can always configure the right version for your application, e.g.

endor-2:~ garex$ /usr/libexec/java_home -v 1.8 -d64 -exec java -fullversion
java full version "1.8.0_45-b14"
endor-2:~ garex$ /usr/libexec/java_home -v 1.7.0 -d64 -exec java -fullversion
java full version "1.7.0_71-b14"

To permanently remove the 1.7.x, read https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html

1
  • with the same comands, but i can not change the default jdk's verion MacBook-Pro:~ chen$ java -fullversion java full version "9+181" MacBook-Pro:~ chen$ /usr/libexec/java_home -v 1.8 -d64 /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home MacBook-Pro:~ chen$ which java /usr/bin/java MacBook-Pro:~ chen$ java -version java version "9" Java(TM) SE Runtime Environment (build 9+181) Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode) MacBook-Pro:~ chen$
    – ncowboy
    Commented Sep 22, 2017 at 6:00
1

Different applications will link to different Java libraries. Older apps will most likely require Java 6 (1.6.0_65), whereas newer apps will link to newer builds of Java respectively.

By way of example, I know that the Mobile Connect app for my old Huawei 3G modem requires Java 6 to be installed, Adobe Photoshop CS6 requires Java 7 (IIRC) and your browsers will most likely request you to run the latest Java, which is Java 8.

You must log in to answer this question.

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