changing the default JVM on OSX Leopard

2008 May 21
by Dick

I’ve been using a bit of Java lately, and the OSX 1.6 JVM seemed pretty stable.

JRuby is the next thing on my geek list, and that runs best on Java 6.

Although the 1.6 JDK was installed in the last system update, it’s not the default:
 

hypnotoad:Desktop $ /usr/bin/java -version
java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05-237)
Java HotSpot(TM) Client VM (build 1.5.0_13-119, mixed mode, sharing)
hypnotoad:Desktop $
hypnotoad:~ $ ls -l `which java`
lrwxr-xr-x  1 root  wheel  74 30 Apr 10:07 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
hypnotoad:~ $ cd /System/Library/Frameworks/JavaVM.framework/Versions/
hypnotoad:Versions $ ls -ld Current*
lrwxr-xr-x  1 root  wheel    1 30 Apr 10:08 Current -> A
lrwxr-xr-x  1 root  wheel    3 30 Apr 10:07 CurrentJDK -> 1.5

I know what you’re thinking. Don’t. Re-pointing those symlinks seems to work, but in fact it breaks all your GUI apps (the ‘A’ is for AWT)::

hypnotoad:Versions $ jconsole
2008-05-20 23:26:20.524 jconsole[680:10b] Apple AWT Startup Exception : ** -[NSCFArray insertObject:atIndex:]: attempt to insert nil
2008-05-20 23:26:20.525 jconsole[680:10b] Apple AWT Restarting Native Event Thread

Instead, you want to open /Applications/Utilities/Java/Java Preferences.App :

'Java Application Runtime Settings' determines the output of 'java -version'

hypnotoad:~ $ java -version
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)
hypnotoad:~ $

( ignore the text about ‘when an applet is executed in this browser’ – Intel Safari is 32-bit, and if you’re on PPC you don’t get JAVA 6 anyway ).

That Steve Jobs has a great sense of humour.

8 Responses leave one →
  1. 2008 September 4
    Robert Rees permalink

    Thanks for the walkthrough. I was wondering how it was done without manually jigging the symlinks. It’s always easy when you know how!

  2. 2009 January 7
    Dahlgren permalink

    Thanks for posting this. I was a few seconds away from changing the symlinks.

  3. 2009 March 5

    Thanks for the tip! This is far better than changing the symlinks…I did that and crashed my eclipse.

  4. 2009 March 25
    John permalink

    Java Preferences.app crashes when I try to open it. What system file / setting does it modify so that I can change it manually?

  5. 2009 March 25

    I just ran it under Instruments (File Activity -> Launch Executable) , and it seems to edit:

    ~/Library/Caches/Java/deployment.properties

    I’d try removing that file if I was you, it should be recreated.

  6. 2009 June 2

    Hi, I was able to get it to work also using this method. But for some reason when I run the java -version command as the root or using sudo, it still gives me java 1.5. The strange thing is that I am executing the same file! I track it down to the physical location and its pointing to the …\A\commands\java

  7. 2009 June 8

    @jamescway I think what Java version to run is set in your home directory. sudo runs java as root so that may be why.

  8. 2009 June 11

    @Dick My solution for getting the root user to work with the correct java was to run the Java Preferences.app as the root user. You can find a few more details at http://www.bangheadonwall.net/?p=118

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS