Mac Neophyte Tips: Changing the default Java version

Even though it worked for me, this fix has given a lot of people problems, so you probably shouldn’t try this. I leave this article online though, maybe it’s of use to someone as a starting point for further investigations. Thanks for all the hate mail though. Ah, the internet is so much fun!

OK, this one might also be widely known but it cost me a few minutes to figure it out, so here it goes: Software Update installs Java 1.6 on 64bit-capable Macs running Leopard. However, this doesn’t mean they change the default runtime version that gets called when you click on a jar file or call code directly from the command line.

OS X’s Java binaries live in a directory called “/System/Library/Frameworks/JavaVM.framework/Versions“. On a 64bit Mac this should contain quite a handful of different runtimes:

lrwxr-xr-x  1 root  wheel    5 Apr 30 12:25 1.3 -> 1.3.1
drwxr-xr-x  3 root  wheel  102 Sep 29  2007 1.3.1
lrwxr-xr-x  1 root  wheel    5 Jan 22 14:00 1.4 -> 1.4.2
lrwxr-xr-x  1 root  wheel    3 Apr 30 12:25 1.4.1 -> 1.4
drwxr-xr-x  8 root  wheel  272 Jan 22 14:00 1.4.2
lrwxr-xr-x  1 root  wheel    5 Jan 22 14:00 1.5 -> 1.5.0
drwxr-xr-x  8 root  wheel  272 Jan 22 14:00 1.5.0
lrwxr-xr-x  1 root  wheel    5 Apr 30 12:25 1.6 -> 1.6.0
drwxr-xr-x  8 root  wheel  272 Apr 30 12:25 1.6.0

This directory also houses two symlinks called “Current” and “CurrentJDK“. As root in Terminal, remove those and replace them with symlinks to the 1.6 runtime:

rm Current*
ln -s 1.6.0/ Current
ln -s 1.6.0/ CurrentJDK

There, all done! From now on “java -version” should return something like:

java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13-120)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_05-b13-52, mixed mode)
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

14 thoughts on “Mac Neophyte Tips: Changing the default Java version

  1. I imagine they don’t change the default version because of compatibility issues, right? But even so, it seems kind of dumb – most Java devs switched to 1.6

  2. I think they did it in order to NOT fragment the Leopard platform. Having to consider two Java versions for OS X (because older Macs can’t upgrade) would be even more of a bummer for Java developers. I guess Apple just opted in favor of a uniform software base for their OS which kind of makes sense.

    Of course, not having the upgrade option for 32bit Macs at all is kind of silly in the first place…

  3. I found that even if I did this, on restart it would drop back to the original default. Which seems to imply there’s another declaration of the java version somewhere else, which gets called on system startup.

    Anyone know where that is?

  4. UP, that hasn’t happened to me. I couldn’t find any reference to a process that might be responsible for doing that on start up, but it might be worth a try to move the older Java versions out of that directory to some other place (in case you need them later)…

  5. Another way to set your default version is to use the Java Preferences tool in /Applications/Utilities/Java. You can easily swap the default version in the utilities’ GUI without root access which is required to change the links as described above.

  6. Thanks kevin, you’re right. However, the Prefs App in Utilities won’t load on my MacBook for some reason – but it does on the Mac Pro… anyway, you’re right!

  7. I did exactly the same, the terminal still shows as 1.6.0_07. I moved java 6 to the last, in the preferences pane too.

    I can’t set the jvm version to 1.5.0. I think I’m gonna uninstall 6, its a shame

  8. Hi
    Please help. I followed your instructions, but now my Eclipse wont start. It returns Error Code=-1.
    I tried to change back to version 1.5.0, using your instructions, but Eclipse still wont start. I also tried downloading Elipse again, same problem :(

  9. Hi Tore, sorry to hear that. Have you tried changing it back? Try starting Eclipse from the command line to see what error messages it throws out!

  10. Hey I had Tore’s problem, and I fixed it
    instead of going back to version 1.5.0, just point to the folder “A”

Comments are closed.