Saturday, January 24, 2009

How to make Ruby and JRuby live peacefully

Similar to each Ruby versions, Ruby and JRuby maintain their own gems separately. While we can use jruby and jirb to specifically tell we want to JRuby version, JRuby does not have jrake or jgem. How do we specify we want to execute rake/gem in Ruby and JRuby?

A solution is to prefix the program with ruby -S and jruby -S like

ruby -S rake
jruby -S rake


or

ruby -S gem list
jruby -S gem list


This way, we explicitly tell which interpreter we want to use and it will automatically find the right program in the right path. Problem solved.

If you want to install multiple Ruby vesions in the same machine, use MultiRuby as described in Dr Nic's Future proofing your Ruby code. Ruby 1.9.1 is coming.