This guide is aimed at developers, although it can be used by beginners if they know what they are after. It is provided as neither [http://www.ruby-lang.org Ruby] or [http://rubyonrails.org Rails] are included as standard in Debian "squeeze". Other Linux RPi distributions may contain this by default.

+

This is a guide to install [http://rubyonrails.org Ruby on Rails] on the Raspberry Pi computer running Debian "squeeze". It will also be useful to people who just require a [http://www.ruby-lang.org Ruby] installation. The guide can be followed by anyone if it all goes right, but when things go wrong, it is often difficult to see what the problem is. It will take several hours to complete and requires an internet connection.

−

THE GUIDE IS STILL DRAFT; AND CURRENTLY DOES NOT LEAD TO A WORKING RAILS, BUT IS CLOSE.

+

The guide has been developed/tested using debian6-19-04-2012. There is not enough room on a standard 2Gb image. I tested with an 8Gb image, but you may get away with 4Gb. Learn how to expand your image [[RPi_Easy_SD_Card_Setup | here]] or [http://www.youtube.com/watch?v=DztSRaFyaVE here].

−

Start with a clean image of Debian "squeeze". There is not enough room on a standard 2Gb image. I tested with an 8Gb image, but you may get away with 4Gb.

+

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

−

The installation was all done from the basic (pre startx) command prompt.

+

# Install prerequisites

+

sudo apt-get install -y git curl zlib1g-dev subversion

−

This method uses the Ruby enVironment Manager ([http://beginrescueend.com RVM]), so first we must install all its prerequisites:

+

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

# Install prerequisites<!-- I suspect there will be many more required to make Rails do anything useful (like sqlite) but waiting until I have a project running to optimise the list against already installed items -->

+

Note: Not installing openssl before RVM will cause you [https://rvm.io/packages/openssl/ grief] later!

−

sudo apt-get install -y git

+

−

sudo apt-get install -y curl

+

−

sudo apt-get install -y zlib1g-dev

+

−

sudo apt-get install -y subversion

+

Now we can use RVM straight from github using:

Now we can use RVM straight from github using:

Line 22:

Line 25:

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

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 scroll down (TODO Confirm this is necessary) until you see "Press 'q' to continue.", then 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.x and Rails. This takes a long time! (3 Hrs) Have a sleep and check in the morning. The above step has been successfully performed on a real RPi, but not managed to complete successfully on Qemu.

+

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:

Now you should have ruby:

Line 33:

Line 39:

Rails 3.2.3

Rails 3.2.3

−

== Current Problems ==

+

== JavaScript ==

−

=== Open SSL ===

+

Rails requires a JavaScript runtime. Any of the following listed [https://github.com/sstephenson/execjs here] will do.

−

Despite having openssl installed, ruby seems to have a problem seeing it. I think this is a [https://rvm.io/packages/openssl/ common] linux problem. The following worked for me, but means waiting a few more hours.

+

I installed node.js using this [http://blog.tomg.co/post/21322413373/how-to-install-node-js-on-your-raspberry-pi blog] by Tom Gallacher. (Note I had to use sudo when doing make install)

−

pi@raspberrypi:~$ rvm reinstall 1.9.3 --with-openssl-dir=/usr/bin

+

−

+

−

=== Java Script ===

+

−

When trying to run the server, you will get a java script error. I have tried installing [http://stackoverflow.com/questions/8991963/why-does-therubyracer-fails-to-build-on-my-debian therubyracer] unsuccessfully, but am currently trying node.js using this [http://blog.tomg.co/post/21322413373/how-to-install-node-js-on-your-raspberry-pi blog] by Tom Gallacher.

+

== Testing Installation ==

== Testing Installation ==

−

In order to test the installation, let's create a simple project.

In order to test the installation, let's create a simple project.

−

In this example the name for our new project is register.

+

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:

+

http://0.0.0.0:3000/pupils

+

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 0.0.0.0 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

−

rails new register

+

== Conclusion ==

−

cd register

+

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 [http://ruby.railstutorial.org/ruby-on-rails-tutorial-book tutorial] it will show you how to deploy to [http://www.heroku.com/ Heroku] (for free), then your website will be as fast as those with proper computers.

−

rails s

+

Revision as of 23:40, 19 May 2012

Contents

Installing Ruby on Rails on Raspberry Pi

This is a guide to install Ruby on Rails on the Raspberry Pi computer running Debian "squeeze". It will also be useful to people who just require a Ruby installation. The guide can be followed by anyone if it all goes right, but when things go wrong, it is often difficult to see what the problem is. It will take several hours to complete and requires an internet connection.

The guide has been developed/tested using debian6-19-04-2012. There is not enough room on a standard 2Gb image. I tested with an 8Gb image, but you may get away with 4Gb. Learn how to expand your image here or here.

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:

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?)

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 0.0.0.0 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

Conclusion

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.