JRuby on Ubuntu Feisty Fawn

If there is one short coming about Ruby, its the limited number of libraries available for it. Sure its growing by the day, but its nowhere in comparison to the Java Programming Language (which will be referred to as just “Java” hence forth). Though they are around the same age, Java has always had the financial and corporate support and through that has established itself in the industry as one of the languages any programmer has gone through. High chances are you’ll learn it in University.

So how do we leverage off Java’s libraries? Lucky for Ruby (and Java) fanatics, the team behind JRuby is bridging the gap between the two languages, by providing an implementation of Ruby on the Java Virtual Machine (JVM).

Sounds almost like a sick and twisted joke. Meshing one with the other, like Frankenstein!

For the People of Ruby:

  • You get to play with all the Java libraries
  • Ability to run Ruby on machines that support the Java Virtual Machine

For the People of Java:

  • You get to play with Ruby

Alright, there are a lot more reasons…

This is great news, especially since Java and the JVM are both free and open source software now.

Note: Note: JRuby is supported by Sun Microsystems, to the extent that they have hired the core developers to continue working full time on JRuby.

Getting Java

I opted to use the Java version 5 to get it running as I’ve seem to have run into trouble getting it working on version 6, but I’ll keep trying. (Problem is the tests run forever!)

sudo apt-get install sun-java5-jdk ant ant-optional junit

Getting JRuby

You can grab the JRuby source via their tarball, or if you prefer, via subversion.

I would recommend installing via Subversion for now, as the current version of JRuby (1.0.0RC3) fails their own tests (at least on my Machine)!

Installing JRuby via Subversion

I like installing via subversion as I can easily update to the latest version of JRuby.

svn co http://svn.codehaus.org/jruby/trunk/jruby/ ~/src/jruby

Installing JRuby via Tarball

Once you get the tarball, untar it.

tar -zxvf jruby-src-1.0.0RC3.tar.gz

I like storing any source related things in my ~/src, you can put it wherever you like (perhaps /usr/src).

mv jruby-1.0.0RC3/ ~/src/jruby

Note: Note: Your filenames/directory names may vary, as the latest version of JRuby as of this writing is 1.0.0 RC3

Setting up the Environment Variables

The environment variable for JAVA_HOME on Ubuntu doesn’t seem to be set up properly for some reason. In fact, I think its broken. So I’ll set it up temporarily in the shell.

export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun-1.5.0.11

JRuby also needs its own environment variable.

export JRUBY_HOME=/home/aizat/src/jruby

Finally its to add the JRuby executables into your PATH

export PATH=$PATH:/home/aizat/src/jruby/bin

Note: Note:

  • If you close the shell, you’ll have to define the JAVA_HOME environment variable again. There are various ways to fix this. One is to stuff these commands into a file and “source file Terminal” them whenever needed. To have them automatically load, append the above lines into ~/.bashrc.
  • Your paths may vary, especially the location of JRuby

Compile and Test

ant test

This will take a while to execute…just go out and have a cup of coffee.

There is no progress bar, so just wait it out.

6 and a half minutes later

So it took about 6 and half minutes to compile and test JRuby on my IBM R52 1.6Ghz Centrino 2Gb Ram laptop. Seems quite decent.

Conclusion

There you have it, you have a working version of JRuby that is (or will be) 100% compatible with Ruby v1.8.5. I haven’t tested it yet, but there are several tutorials you can start with.

Just pull up jirb and play along, it’ll look and feel like Ruby.

I’ll have to look at performance issues when doing this. But hey Ruby isn’t a speed king to begin with. There are various articles covering performance issues with different implementations of Ruby.

There is also a growing wiki on JRuby, so if you have anything interesting, add it to that!

Looking Further Ahead

I am looking at this to harness the power of Ruby on the S60 platform for my new Nokia e61i. There exists an implementation of of Ruby for Symbian phones, but its not mature (some might consider JRuby isnt as well!)

I chose to use JRuby instead of Ruby for Symbian because Java already has all the APIs I need. Also worse comes to worse, the experience of knowing JRuby over Ruby for Symbian is a lot more worth it.

Wish me luck, I hope I don’t break my phone!

This entry was posted in Installing JRuby, Ubuntu Feisty Fawn. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Ahmad Amr
    Posted 24 September, 2007 at 1:00 am | Permalink

    Thanks a lot, I really needed that environment variable part

  2. Jesse
    Posted 24 October, 2007 at 6:10 am | Permalink

    Very helpful. Thanks!

One Trackback

  1. By 32nd diary(2007-06-19) on 19 June, 2007 at 8:47 pm

    [...] Ubuntu¤ÇJRuby¤òư¤«¤·¤¿¤Î¤Ç¡¤¤½¤Î¤È¤­¤Î¥á¥â¤ò»Ä¤·¤Æ¤ª¤³¤¦¡¥ »²¹Í¤Ë¤·¤¿¤Î¤ÏJRuby on Ubuntu Feisty Fawn¤Ç¤¹¡¥ [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*