MacOS – What sets the Java Virtual Machine

javamacos

I'm not understanding how my Java environment is getting set up. If I have multiple versions of Java installed how does the correct version get selected when I start a Java dependent application?

I have both Apple's original 1.6 version of Java and Sun's more recent 1.8 installed.

If I type java -version I get

java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)`

ls -l /usr/bin/java produces lrwxr-xr-x 1 root wheel 74 Jun 16 2014 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java where Current is pointed at Apple's 1.6 Java install.

Best Answer

The java executables in /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java are not the executables that just run the java compiler etc. They are wrappers that use /usr/libexec/java_home to find the executables.

Apple's Java 6 is in /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin

Run /usr/libexec/java_home -V to see all the Java VMs you have installed.