Java Version Management on OSX

Been doing Java on OSX for a long time.  Either everybody else knows this and nobody told me, or this is a well kept secret.  Turns out there’s some convenience methods on OSX for toggling out the active java version via java_home.  What a surprise.  There’s also a JAVA console in system preferences!  Who knew!

Probably most of you don’t have to do this often, but I work on projects requiring 1.6 32 bit, 1.6 64 bit, 1.7, and 1.8, so this was a godsend.

Note that I am on OSX 10.8.3

System Prefs

To launch the Java Control Panel on Mac OS X (10.7.3 and above):

  • Click on Apple icon on upper left of screen.
  • Go to System Preferences
  • Click on View
  • Click on Java icon to access the Java Control Panel.

Swapping Versions

What I did, once I learned of this, is create some simple scripts to toggle between the versions I had installed.

set1.6-32.sh

#!/bin/bash
export JAVA_HOME=`/usr/libexec/java_home -v 1.6 -a i386`
java -version

CORRECTION: The latest java update for mac removed the 32bit mode

set1.6-64.sh

#!/bin/bash
export JAVA_HOME=`/usr/libexec/java_home -v 1.6 -a x86_64`
java -version

set1.7.sh

#!/bin/bash
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
java -version