Friday, 5 September 2014

Installing JRuby on Raspberry Pi

I am persisting with my project to get Ruby Shoes 4 up and running on my Raspberry Pi. I really believe that Shoes will be a great medium for kids to learn programming. I've now completed the next step, getting JRuby up and running on Raspberry Pi.

I'm using rbenv to manage my Ruby installations on my Raspberry Pi as I explained in Installing Ruby on Raspberry Pi.

Of course, you need Java to install and run JRuby. I've found that there is a bug with the OpenJDK version of Java that stops JRuby working. So I installed the Oracle version:

sudo install oracle-java7-jdk

After installing Oracle's Java, like me, you'll probably end up with multiple versions of Java on your Raspberry Pi. Thanks to Bill Connelly for dropping a big hint on the Raspberry Pi forums, I was able to easily set Oracle's Java as the default by running the following commands and selecting the correct option:

sudo update-alternatives —config java
sudo update-alternatives —config javac

After that I simply had to use rbenv to install version 1.7.13 of JRuby:

rbenv install jruby-1.7.13

It takes quite a while and keeps the Raspberry Pi fully occupied during the installation but you can leave it running and come back later.

I installed JRuby 1.17.13 instead of the newer JRuby 1.7.14 as there was a warning on Shoes 4 GitHub that there is an issue with the newer version.

As I have Ruby 2.1.2 as the default Ruby on my Raspberry Pi, I set up a new directory, shoes, in which I set JRuby as the default. These are the commands that I used:

cd ~/raspberryruby
mkdir shoes
cd shoes
rbenv local jruby-1.17.13

Finally I launched JRuby:

~/raspberryruby/shoes$ ruby -v
jruby 1.7.13 (1.9.3p392) 2014-06-24 43f133c on Java HotSpot(TM) Client VM 1.7.0_40-b43 [linux-arm]

When you run JRuby, it takes a long time to load. I think this is not just because of the time to load the Java Virtual Machine in which JRuby runs but also due to a small bug that results in JRuby displaying the following warning:

pi@raspberrypi:~/raspberryruby/shoes$ irb
Java HotSpot(TM) Client VM warning: You have loaded library /home/pi/.rbenv/versions/jruby-1.7.13/lib/jni/x86_64 Linux/libjffi-1.2.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
irb(main):001:0> 

The warning doesn't have any adverse effect on JRuby, everything works as expected. This bug has already been reported to the JRuby team and hopefully will get fixed soon.

Now I can start on getting Shoes to run on my Raspberry Pi. 

No comments: