JRuby setup

On this page, we will see how to install JRuby and that it can co-exist with the MRI ruby we have been working so far. In fact switching between the both is almost a piece of cake. We will be doing this on a windows box [Mac or *nix should NOT be a rocket science]

Check Java Version

Should be 1.7 or higher [I have been working with 1.7 for long time now, however there is JRuby for earlier versions too]

check_java

Download JRuby archive

jruby_download

Un-archive and save it

I downloaded the .zip file, extracted the archive to c: drive as follows.

unarchive_jruby

Install pik

pik is for windows as RVM (ruby version manager) for *nix enviroments. If you are on *nix, I needn’t be telling you that RVM is an awesome piece of whatever 🙂 Though many of us are still stuck with …you know…

install_pik

Run install script

pik_install_configure

Current pik Rubies?

Let’s see what Rubies did pik pick up (pik pik pik pick pick….haha)

pik_list_before_jruby

Add JRuby to pik

pik_add_jruby

pik list again

pik_list_after_jruby

That is it !

  • We have successfully installed JRuby and configured it with pik.
  • We used pik because we wanted both MRI and JRuby to co-exist
  • However, we can always turn off one over the other [with pik of course]

Switching between MRI and JRuby

When we do “pik list” you can see “*” (star) against the Ruby 200 , that means the current environment is pointing to MRI Ruby in my case Ruby version 2.xx

When you would like to use JRuby, switch with “pik use” command as follows. You can verify that the current environment uses JRuby by “pik list”

pik_use_jruby

Closing Thoughts

Will both MRI and JRuby use the same gems installed ?

There are some shared, but not all really, pik manages the gem lists that JRuby and MRI ruby has. We do NOT need to sweat over that. In fact, we will let bundle manage that for us.

When in doubt ,run “bundle install’ or “bundle update” after switching to the appropriate MRI or JRuby , from that point, the environment would point to the one we intend to use.

We will see how by executing some examples on next page.