How To Build JRuby on OS X
May 11, 2007The JRuby has been getting a lot of press lately. It’s got support in NetBeans, and is getting a lot of support from Sun. It looks like it’s a popular topic at this year’s JavaOne as well.
JRuby is exciting because it gets Ruby a backdoor to the corporate world. Tomcat and Java 1.5 are common enough in big business these days, and with JRuby nearing 1.0 we’ll soon have a way to write Ruby code and not have to ruffle the feathers of sys admins with new dependencies for deployment.
Here’s how to get JRuby up and running on your Mac.
What You’ll Need
Download JRuby
First you’ll need to download the JRuby source, since we’ll be building it ourselves. You can get the current release from the JRuby Homepage. I used version 0.9.9 when writing this.
Install the Developer Tools
If you haven’t already, you’ll need to install the OS X Developer Tools. You can find them on the install DVDs that came with your Mac. This gets us Ant, which we’ll need later. If you already have Ant installed from somewhere else, just make sure it’s version 1.6.2 or greater (the Developer Tools version is 1.6.5).
Set Your Environment Variables
Add these two lines to your ~/.bash_profile:
export JAVA_HOME='/System/Library/Frameworks/JavaVM.framework/Home' export ANT_HOME='/Developer/Java/ant'
Build JRuby and Run the Tests
Now you should have your build environment all set and ready to go. First extract the source files and go into the directory that is created:
tar xvzf jruby-src-0.9.9.tar.gz cd jruby-0.9.9
Copy the provided JUnit lib over to Ant:
cp lib/junit.jar /Developer/Java/ant/lib/.
And finally:
ant test
You should see a bunch of output, and after about a minute or so you should see all the included tests (hopefully) pass. Now you can run one of the samples just as a sanity check:
bin/jruby samples/fib.rb
And there you have it, JRuby on OS X ready to go.