Manage multiple Java versions in Mac OS X

Apple does no longer provide Java Runtime Environments (JRE) or Java Development Kits (JDK) for Mac OS X. The last JRE from Apple was version 1.6 (Java 6).

AB-iMac:/ AndyBrunner$ ls -l /System/Library/Frameworks/JavaVM.framework/Versions
total 64
lrwxr-xr-x 1 root wheel 10 26 Jun 09:44 1.4 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 26 Jun 09:44 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 26 Jun 09:44 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 26 Jun 09:44 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 26 Jun 09:44 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 26 Jun 09:44 1.6.0 -> CurrentJDK
drwxr-xr-x 7 root wheel 238 26 Jun 09:44 A
lrwxr-xr-x 1 root wheel 1 26 Jun 09:44 Current -> A
lrwxr-xr-x 1 root wheel 59 27 Jun 13:26 CurrentJDK -> /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/

If you need newer Java versions (e.g. for Eclipse Luna), you can install newer JREs and JDKs from Oracle directly from their website http://www.oracle.com/technetwork/java/javase/downloads/index.html.

The Mac OS X system allows the installation of multiple instances of Java, e.g.:

AB-iMac:/ AndyBrunner$ ls -l /Library/Java/JavaVirtualMachines/
total 0
drwxr-xr-x 3 root wheel 102 27 Jun 08:03 jdk1.7.0_60.jdk
drwxr-xr-x 3 root wheel 102 27 Jun 13:02 jdk1.8.0_05.jdk

Note that these products are installed in /Library/ as opposed to /System/Library/ used by the original Apple download.

The currently used default JRE is shown with

AB-iMac:/ AndyBrunner$ java -version
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)

For consistency, you should also make sure that the CurrentJDK link points to the JDK you need most often (see first screenshot).

If needed, this link may be changed with

AB-iMac:Versions AndyBrunner$ cd /System/Library/Frameworks/JavaVM.framework/Versions/
AB-iMac:Versions AndyBrunner$ sudo rm CurrentJDK
AB-iMac:Versions AndyBrunner$ sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/ CurrentJDK