FR:RPi Ruby on Rails

Revision as of 23:39, 14 June 2013 by Xavier (Talk | contribs) (french translation. traduction en cours. source: 18/01/2013 20:01)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Installation de Ruby on Rails sur Raspberry Pi

Voici un guide pour installer Ruby on Rails sur l'ordinateur Raspberry Pi tournant sous Debian "squeeze". Il sera également utile aux personnes qui ne souhaitent installer que Ruby. Tout le monde peut suivre ce guide dans le cas où tout se passe bien, par contre, dans le cas contraire, il est souvent difficile d'identifier le problème. Une connexion internet est requise et il faudra plusieurs heures pour terminer le guide.

Il a été développé et testé avec debian6-19-04-2012. Il n'y a pas assez de place sur une image standard de 2Go. J'ai fait les tests avec une image de 8Go, mais 4Go devraient convenir. Voyez comment étendre l'image ici ou .

The installation was all done from the basic (pre startx) command prompt. We will use Ruby Version Manager (RVM), so first we must install all its prerequisites:

# Install prerequisites
sudo apt-get install -y git curl zlib1g-dev subversion

You might come across the error '404 not found', then try update your APT package index:

# Update APT package index
sudo apt-get update

The above is enough to proceed, but we will also need the following later, so whilst we're in the mood for apt-getting:

# Additional Ruby dependencies
sudo apt-get install -y openssl libreadline6-dev git-core zlib1g libssl-dev
sudo apt-get install -y libyaml-dev libsqlite3-dev sqlite3
sudo apt-get install -y libxml2-dev libxslt-dev
sudo apt-get install -y autoconf automake libtool bison

Note: Not installing openssl before RVM will cause you grief later!

Now we can use RVM straight from github using:

curl -L | bash -s stable --rails

Note: With my default Debian image and keyboard map, it was very hard to get a | (pipe) character. I got it by pressing AltGr+|

When run, you will get some messages about requirements for Ruby. You need to press 'q'. Note the computer may not react straight away as it is 'thinking'. After a few seconds, the script will download and compile ruby 1.9 and Rails. This takes a long time! (3 Hrs) Have a sleep and check in the morning.

At the end of the installation, RVM suggests that you have to run a script in order to enable Ruby. (I think I only had to do this once?)

pi@raspberrypi:~$ source ~/.rvm/scripts/rvm

Now you should have ruby:

pi@raspberrypi:~$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [armv61-linux-eabi]

And you should have a rails command:

pi@raspberrypi:~$ rails -v
Rails 3.2.3


Rails requires a JavaScript runtime. Any of the following listed here will do. I installed node.js using this blog by Tom Gallacher. (Note I had to use sudo when doing make install)

Test de l'installation

In order to test the installation, let's create a simple project. In this example the name for our new project is school.

pi@raspberrypi:~$ rails new school
pi@raspberrypi:~$ cd school
pi@raspberrypi:~$ rails g scaffold Pupil name:string form:string
pi@raspberrypi:~$ rake db:migrate
pi@raspberrypi:~$ rails s

All being well you will now have a running server with database back end, which you can point a browser at.

Note: You can't use 'class' as a field name, so I chose 'form'.

If you do the above in an X-windows terminal, then point the Raspberry-Pi browser to:

You should then be able to Create, Read, Update & Delete (Often called CRUD) pupil records in your database.

Alternatively, if you have another computer on the same network, you can point its browser at the RPi substituting the in the above address for the real RPi one. If you don't know the address of your RPi, then use the following command in a terminal:

hostname -I


We have a working installation of Ruby on Rails. It is very slow but just about usable. If this is your introduction to Ruby on Rails please don't let the speed put you off. If you follow this fantastic tutorial it will show you how to deploy to Heroku (for free), then your website will be as fast as those with proper computers.