Changing Default Java Version on OS X

OS X comes with Java support already included – current versions of OS X 10.5 have Java 1.3, 1.4, 1.5 and 1.6 installed. By default, Java 1.5 is currently the active version (on OS X 10.5.6).

Java is installed under /System/Library/Frameworks/JavaVM.framework. Folder Versions contains various Java versions and links to them. A folder named A contains the current active default version. When switching between versions, this folder’s content is replaced.

I first thought it would be sufficient to change Current and CurrentJDK links to point to the desired Java version. In fact, it partially works, e.g., the new version is active on the Terminal afterwards. However, Java applications started from the GUI didn’t work any more (e.g., Eclipse, FreeMind, NeoOffice). In the system’s log I found entries like “[JavaAppLauncher Error] unable to find a version of Java to launch”.

If you changed these soft links and want your configuration to work again, best is to recreate them so that Current points to A and CurrentJDK points to 1.5. On the terminal, switch to /System/Library/Frameworks/JavaVM.framework/Versions and do (mind that you must enter your admin password in order to be able to do these changes):

$ sudo ln -sfh A Current
$ sudo ln -sfh 1.5 CurrentJDK

If you don’t want to use the terminal or if you somehow destroyed your Java installations, you can restore the whole JavaVM.framework directory from a recent Time Machine backup (if you have one). I tried this method out and works good and fast.

The right way to change the system’s default Java version is to use the Java Preferences application (located in Applications/Utilities/Java). If you change the order of Java versions there, the content of directory A will be changed (at least that’s what I found out – and it makes sense). This way everything works as expected and Java applications start without errors.

Here’s a screenshot of my Java Preferences: I dragged “Java SE 6” to the first place, so it became my new default Java version for applications.

If you want to read more about Java and OS X, Apple provides a good introduction here: Java Fundamentals. Choose “Java Development Guide for Mac OS X” first. It also explains some of Apple’s concepts regarding Java.

Comments are closed.