JRuby Part I – Installing JRuby
*** Updated ***
I’m working on re-architecting a RoR app and wanted to check out JRuby rather than sticking with MRI. Here’s what I did to install it on my MacBook Pro running Leopard.
1. Download JRuby at http://dist.codehaus.org/jruby/jruby-bin-1.1.4.zip
2. Unzip the file to /opt
sudo unzip jruby-bin-1.1.4.zip /opt/
3. Create a symlink to JRuby so that I don’t have to type in the version number.
sudo ln -s /opt/jruby-bin-1.1.4 /opt/jruby
For Ubuntu 8.10LTS Hardy Heron, please enter following command to facilitate /usr/bin/env jruby.
sudo ln -s /opt/jruby/bin/jruby /usr/bin/jruby
4. Add the following line to /etc/profile
export $PATH:/opt/jruby/bin
5. Add following alias to make my life easier.
alias jr='jruby -S'
alias jss='jruby -S script/server'
alias jsgen='jruby -S script/generate'
alias jscon='jruby -S script/console'
6. Install absolute bare essential gems.
sudo jruby -S gem install jruby-openssl rails mongrel jdbc-mysql activerecord-jdbcmysql-adapter activerecord-jdbcsqlite3-adapter jdbc-sqlite3 hpricot
I did basically the same thing on my Ubuntu and it works just fine this way. If you want and you’re really brave, you can replace the symlink for ruby in /usr/local/bin with jruby to completely replace MRI.
I found that Rails works well except for the fact that libxml isn’t available with JRuby due to the fact that anything with C extensions will not work. Another thing that I have to remember that in database.yml of a Rails app, the adapter must have jdbc before the name. e.g. adapter: sqlite3 => adapter: jdbcsqlite3. If you run script/generate without jruby -S, you’ll get an error if your adapter is now using jdbc.
I’ll post my experience with JRuby in upcoming posts. After I’m done with JRuby, I’ll be moving to YARV, and Rubinius last since I’ve been playing with Rubinius for awhile.
