Wednesday 2 July 2014

Installing Ruby on Raspberry Pi

One of the reasons that I bought my Raspberry Pi was for our seven-year old to use it to learn about computers. She's already played with Scratch on my laptop. She's tried the Python games out on the Raspberry Pi. I guess there's even a possibility that she may get some exposure to Raspberry Pi at school. Perhaps I should start referring to it as "our" Raspberry Pi rather than  "my" Raspberry Pi.

I'm really keen for her to learn more about computers than using Microsoft Office and Google Drive. When the "Hello Ruby" children's book project was launched on Kickstarter, I quickly backed the project. If the project is on schedule the book should arrive during Hannah's summer holidays.

So I thought I'd install Ruby on our Raspberry Pi before the book arrives. I know a little Ruby and quite like it. More than that I've found it very useful on a number of occasions. I don't know Python at all so I'm planning to use Ruby on  our Raspberry Pi.

Installing Ruby wasn't difficult. I followed the clear instructions relating to Ruby and rbenv at Raw Syntax. There seems to be one slight omission in the instructions, you need to add rbenv to your PATH environment variable before trying to run rbenv to install Ruby.

After installing rbenv from Github, I created a .bash_profile file in my home directory with the following contents:

    PATH="/home/pi/.rbenv/bin:$PATH"
    eval "$(rbenv init -)"

I was then able to proceed to install the latest release of Ruby using this command:

    rbenv install 2.1.2

It takes a long time to compile Ruby on a Raspberry Pi so I left it running whilst I went for dinner. When I came back I was disappointed to find that the Ruby build had failed on the last stage - building the documentation. The error message was [rdoc] Error 137. I quickly googled the error and found a suggestion to install Ruby without its documentation. That was fine for me as when I have a question about Ruby I either look in The Pick Axe or check the online documents. This time I installed Ruby using:

    CONFIGURE_OPTS="—disable-install-doc" rbenv install 2.1.2

This time the install completed successfully and I now have Ruby installed on our Raspberry Pi


Ruby on Raspberry Pi
Click to Enlarge
Footnote: I haven't quite finished yet. Whilst I can run Ruby on our Raspberry Pi by using a terminal on my Mac, I'm having problems getting rbenv to work using LXTerminal on the Raspberry Pi. I can run Ruby by specifying the full path to the file but that defeats some of the purpose of installing rbenv. I'm pretty sure that it's something to do with LXTerminal and shells. I need to find out.

LXTerminal does not seem to run bash by default so the answer is either to select bash from the pop-up menus (Other -> Bash) or enter the following command in LXTerminal:
    
    lxterminal -e "bash -il"

3 comments:

Anonymous said...

http://awsyntax.com/blog/getting-started-with-raspberry-pi/

is dead

Peter W A Wood, Programmer said...

I made a typing error in the URL which I have now corrected.

Peter W A Wood, Programmer said...

I'm looking into using chruby instead of rbenv for managing Ruby versions. I want to check if it will run in the standard Raspbian terminal first.

I'll write a new article if I decide to do so.