0

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.

  • Looks like your /usr/bin/java is still Java 6 but in your .bashrc or .bash_profile the Java 8 installer has appended its path in front of the original one - so that when you just do java by default it picks up the Java 8 version. – Ambidextrous May 6 '15 at 2:13
  • which java produces /usr/bin/java so I wouldn't think it would be the path variable that's the issue. I've also heard that the shell is irrelevant to the environment in which applications are launched, which is why my browsers all successfully use Sun's 1.8 install while my path is still pointed at the old Apple version. – Keith May 6 '15 at 3:04
  • @Keith /usr/bin/java is not used by web java that is controlled by the Java control panel – user151019 May 6 '15 at 10:20
1

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.

0

In your current terminal session you can select the JVM using /usr/libexec/java_home -v 1.8 see java_home --help for more options.

For GUI applications you should set JAVA_HOME as an environment variable. Setting Environment variables in Mac OS is explained in Environment variables in Mac OS X on StackOverflow. Be aware that ~/.launchd.conf is deprecated: man launchd.conon Yosemite

...launchd.conf is no longer respected by the system. ...

  • I wish I could select more than one answer because yours was also helpful. Unfortunately @Mark's explanation that the executables are really wrappers was the direct answer to my question. The environment variables stuff you pointed to is also really helpful. Thank you. – Keith May 9 '15 at 8:05

You must log in to answer this question.

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