[ Content | View menu ]

Installing Java 7 and JRuby on Mac OS X Lion

Mark Mzyk | August 24, 2011

I currently have a project that I’m evaluating using JRuby for. The first step in the evaluation is of course to set everything up. While I could have installed JRuby and let it run with the version of Java already available on Mac OS X Lion, I opted to be on the edge. That means installing the latest OpenJDK Mac OS X port of Java 7 and installing JRuby on top of it.

These are the directions of how I did that.

These steps can be found in other places, but my hope is that by collecting them all in one place I make it easier for others.

First stop, Java.

Java 7 is not yet officially out for Lion, but it is possible to install a Mac OS X port early release version without too much trouble.

The directions are available on the OpenJDK Mac OS X Port page.

First make sure you meet the prerequisites, such as having a 64 bit capable machine, having Lion, having the latest Xcode installed (Version 4.1, available through the Mac app store for free).

Once you’ve verified the prerequisites and installed Xcode 4.1 if you need it, you’ll need to download Apple’s preview of Java 7. This doesn’t install Java 7, but it is necessary so that you have the proper APIs for Java 7 to work on the Mac.

To download it, go to connect.apple.com.

You will need to log in using your Apple Id and password. You can register if you don’t have one.

Once in, navigate to the Java section. You’ll then want to download the latest disk image for Lion, which as of this writing is Java for 10.7 – 11M3504 (Disk Image).

Once the download is complete, run the disk image and install it.

Next you’ll need to follow further directions from the Mac OS X Ports page, found here.

The directions will tell you how to install a preview version of Java 7 on Lion. You can either build it from source or download an unofficial build. I opted to download the latest unofficial build, which is OpenJDK-OSX-1.7-universal-20110822.dmg at the time of this writing.

Once downloaded, install it.

Now Java 7 is on your system, but it won’t be the default Java. To make it the default Java, launch:

/Applications/Utilities/Java Preferences.app

and drag both of the OpenJDK 7 entries to the top of the list. Then close the Java Preferences app. Java 7 is now installed on your system and is the default.

To make sure Java 7 is the default, launch a terminal and run java -version.

You should see output that looks similar to this:

openjdk version "1.7.0-internal"
OpenJDK Runtime Environment (build 1.7.0-internal-b00)
OpenJDK 64-Bit Server VM (build 21.0-b17, mixed mode)

It’s onto JRuby.

Download the latest JRuby from jruby.org (as of this writing, it is 1.6.4).

I downloaded the tar ball. Extract it. It will place a jruby-1.6.4 folder wherever you extracted it to.

Move the folder to the location you want it on your system, if it isn’t already there.

Add the bin folder from the jruby folder you extracted to your system path. Good directions can be found at Hathology.com. Note that those directions modify the path for every user on the system, not just a single user.

Once that is done, close and restart any terminals you have open. Then type jruby -v and you should see this:

jruby 1.6.4 (ruby-1.8.7-p330) (2011-08-23 17ea768) (OpenJDK 64-Bit Server VM 1.7.0-internal) [darwin-x86_64-java]

Success. You’re now running JRuby with Java 7 on Mac OS X Lion.

Since the Java 7 isn’t an official version, I can’t promise there won’t be bugs or other weirdness, but that’s the fun of living on the edge.

JRubyConf Post Design / CC License 

 

 

 

Filed in: General.

10 Comments

  1. Comment by bApTizE:

    Hi Mark,
    Has this changed! this looks complicated, i’m new to mac and i don’t want to start messing it up!

    Thanks.

    February 10, 2012 @ 19:57
  2. Comment by Mark Mzyk:

    Things have changed a bit. While Oracle has not yet released Java 7 for the Mac, they have announced plans to do so in Q2 of 2012.

    See: http://campustechnology.com/articles/2011/10/06/oracle-previews-java-se-7-for-mac-os-x-unveils-java-se-roadmap.aspx

    Oracle has also released a preview version of Java 7, which you can download from here:

    http://jdk7.java.net/macportpreview/

    That will be simpler than above, but I don’t know what it contains. As for the above instructions, even if you did screw something up, it’s just a matter of telling the system to use the old system Java by putting it back at the top of the Java Preferences app (look for those steps in the blog post).

    I should also note that the version numbers have likely changed since I made this post, as I haven’t checked recently.

    Hope that helps.

    February 12, 2012 @ 21:59
  3. Pingback from Java 7 en Mac OS X Lion « Gerardino's Tech:

    […] Programmer’s Paradox – Installing Java 7 and JRuby in Mac OS X Lion […]

    March 27, 2012 @ 18:56
  4. Comment by Marty Goldstein:

    These are useless instructions. Why publish such useless ‘information’.

    April 7, 2012 @ 20:17
  5. Comment by Mark Mzyk:

    Hey Marty,

    Sorry you found these instructions useless. Could you elaborate on why you found them that way? They worked for me, although at this point they are getting somewhat old, as I noted in a comment above.

    At some point, once Java 7 is officially out for the Mac there will be no point in following these instructions, but in the mean time, if you tell me why you didn’t find them helpful perhaps I can update them to be more informative.

    Thanks.

    April 9, 2012 @ 10:10
  6. Comment by bApTizE:

    Marty, your post is useless and considered troll. His instructions worked for me, i have java 7 installed and working just fine.

    April 10, 2012 @ 10:18
  7. Comment by Jose:

    Hi, unfortunately they didn’t work for me.

    I installed java7 and it is listed in Java Preferences, but from the terminal always java -version displays I’m using java 6.

    I noticed java 6 is marked as system, meanwhile java 7 isn’t.

    Thanks.

    July 16, 2012 @ 18:29
  8. Comment by Mark Mzyk:

    Hey Jose,

    It’s been a while since I’ve messed with Java 7 on the Mac, but I do recall that for it to work, you’ll need to move it to the top of the Java preferences, so that your OS will use that Java first. Java 6 is marked as system, but that doesn’t have anything to do with which Java is used. After you update the Java preferences, it will also likely take a restart of the terminal to show you the new version of Java running.

    Hope that helps.

    July 16, 2012 @ 20:46
  9. Comment by Jose:

    Hi Mark,

    thank you for the fast response. Actually I was a bit surprised as it seems it worked fine for everyone but me. As a unix guy I decided to create new symlinks to java 7:

    /System/Library/Java/JavaVirtualMachines/1.7.0.jdk -> /Library/Java/JavaVirtualMachines/1.7.0.jdk

    `–> ls -l /System/Library/Frameworks/JavaVM.framework
    total 64
    lrwxr-xr-x 1 root wheel 27 14 Jun 18:05 Classes -> Versions/CurrentJDK/Classes
    lrwxr-xr-x 1 root wheel 28 14 Jun 18:05 Commands -> Versions/CurrentJDK/Commands
    lrwxr-xr-x 1 root wheel 27 14 Jun 18:05 Frameworks -> Versions/Current/Frameworks
    lrwxr-xr-x 1 root wheel 24 25 Apr 14:53 Headers -> Versions/Current/Headers
    lrwxr-xr-x 1 root wheel 24 14 Jun 18:05 Home -> Versions/CurrentJDK/Home
    lrwxr-xr-x 1 root wheel 23 14 Jun 18:05 JavaVM -> Versions/Current/JavaVM
    lrwxr-xr-x 1 root wheel 29 14 Jun 18:05 Libraries -> Versions/CurrentJDK/Libraries
    lrwxr-xr-x 1 root wheel 26 14 Jun 18:05 Resources -> Versions/Current/Resources
    drwxr-xr-x 11 root wheel 374 17 Jul 00:38 Versions

    That way it seems to work as expected. I also tried restarting (terminal, sessions even a reboot with no results).

    Best.

    July 17, 2012 @ 11:54
  10. Comment by Mark Mzyk:

    Not sure why it didn’t work for you Jose, but glad you figured it out. Thanks for sharing your solution.

    July 17, 2012 @ 12:37