RPi Ruby

Installing Ruby on Raspberry Pi
This is a guide to install Ruby on the Raspberry Pi computer running Debian "squeeze".

There are multiple ways to install Ruby, each with their own pros and cons. The guide provides step-by-step instructions for two methods, and points to another page which contains a third method. All methods require an Internet connection.

The guide has been developed/tested using debian6-19-04-2012. Depending on how you choose to install Ruby, there may not be enough room on a standard 2Gb image. This is especially true if you've already installed anything else. Learn how to expand your image here or here.

Pros

 * Very easy
 * Supported by the Debian team.
 * Uses only 10MB of hard drive space
 * Does not install RubyGems or any gem add-ons (optional tools/features that you may not need)

Cons

 * Installs Ruby v1.8.7, an older release of Ruby (current release is 1.9.x)
 * Installs Ruby v1.8.7p302, an older version of Ruby 1.8.7 (current release in the 1.8.7 family is Ruby v1.8.7p358)
 * Does not install RubyGems or any gem add-ons (optional tools/features that you may need and will have to install yourself)

Commands
Installing Ruby from the Debian repository is fantastically simple: sudo apt-get install ruby Done!
 * 1) Install Ruby from the Debian repository

Installing Ruby From The Source Code
You can also install Ruby by downloading and compiling the source code. You can download the source code from the official Ruby FTP server.

Pros

 * You can install a specific release/version of Ruby
 * Access to newer releases/versions than what's in the Debian repository
 * Might install RubyGems and some gem add-ons (optional tools/features that you may need)

Cons

 * Compiling can be a tricky business, and compiler options may change between releases or versions
 * Little-to-no help for beginners if something goes wrong during compilation or installation
 * You are responsible for patching/upgrading to releases/versions that are more stable and/or more secure; can't rely on the Debian repository!
 * Could require 250MB (or more!) free space during the installation process. That's nearly all the available space on the standard 2GB image.
 * Might install RubyGems and some gem add-ons (optional tools/features that you may not need)

Releases
There are two main releases of Ruby: v1.8.7, and v1.9.x. Discussion of the differences between these releases is beyond the scope of this guide. In a nutshell: The core Ruby language has not significantly changed between releases, but v1.9.x includes a variety of optimizations and a few popular gems (optional tools/features that are utilized by a number of Ruby programmers).

Ruby v1.8.7
Ruby v1.8.7 is still actively maintained by the Ruby community, although it is no longer being actively developed. Put another way, it gets bug fixes, but no new features. Ruby v1.8.7 is regularly used for older Ruby on Rails applications.

Pros

 * Only requires 30MB free space during installation
 * Uses 15MB of hard drive space
 * Does not install RubyGems or any gem add-ons (optional tools/features that you may not need)

Cons

 * Older release (but still supported)
 * Does not install RubyGems or any gem add-ons (optional tools/features that you may need and will have to install yourself)

Commands
Compiling Ruby from the source code requires that a few other development packages are already installed. sudo apt-get install libreadline5-dev libyaml-dev libssl-dev You can download the source code from the official Ruby FTP server. The following instructions use Ruby v1.8.7p358, the most recent 1.8.7 version at the time of this writing. If the following "wget" command fails to download anything, then the Ruby team has likely released a newer version of Ruby v1.8.7 - you'll have to check their site and change these instructions accordingly. cd ~ wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.7-p358.tar.gz gunzip ruby-1.8.7-p358.tar.gz tar -xf ruby-1.8.7-p358.tar rm ruby-1.8.7-p358.tar Compile and install Ruby v1.8.7 cd ruby-1.8.7-p358 ./configure --prefix=/usr make sudo make install Delete the source code (we need that space!) cd .. rm -fR ruby-1.8.7-p358
 * 1) Install development dependencies for compiling Ruby
 * 1) Download, unzip, and untarball the source code, and then free up some precious disk space
 * 1) Configure, compile, and install
 * 1) (wait 3 minutes)
 * 1) (wait 23 minutes)

Ruby v1.9.x
Ruby v1.9.x is actively maintained and developed by the Ruby community. It gets both bug fixes and new features/optimizations. Ruby v1.9.x is regularly used for new Ruby on Rails applications.

Pros

 * Newest release of Ruby
 * Uses 15MB of hard drive space, even with the additional tools that don't come with the other releases
 * Installs RubyGems and some popular gem add-ons (optional tools/features that you may need)

Cons

 * Requires 250MB of free space during installation - this is nearly all the available space on the standard 2GB image.
 * Installs RubyGems and some popular gem add-ons (optional tools/features that you may not need)

Commands
These instructions have been measured almost to the megabyte - the amount of available space on a standard 2GB image dips down into low single-digits during these instructions. If you have installed anything, including system updates, there is an excellent chance that you will run out of available drive space and this process will fail. And if the root drive is full, the OS may stop functioning and become unbootable, requiring a re-imaging of your boot SD card. You have been warned!

Compiling Ruby from the source code requires that a few other development packages are already installed. sudo apt-get install libreadline5-dev libyaml-dev libssl-dev You can download the source code from the official Ruby FTP server. The following instructions use Ruby v1.9-stable. While this makes downloading the latest version easy (it is always named the same), the unzipped, untarballed folder will have a different name. For me, the file "ruby-1.9-stable" contained the folder "ruby-1.9.3-p194". You will likely have to alter these instructions based on the version that is included in Ruby v1.9-stable. cd ~ wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.9-stable.tar.gz gunzip ruby-1.9-stable.tar.gz tar -xf ruby-1.9-stable.tar rm ruby-1.9-stable.tar Discover which version is the current "stable" version, compile, and install ls -ld ruby-1.9.* cd ruby-1.9.3-p194 ./configure --prefix=/usr make sudo make install Delete the source code (we need that space!) cd .. rm -fR ruby-1.9.3-p194
 * 1) Install development dependencies for compiling Ruby
 * 1) Download, unzip, and untarball the source code, and then free up some precious disk space
 * 1) Find the correct folder name - yours might be different
 * 1) Configure, compile, and install
 * 1) (wait 3 minutes)
 * 1) (wait 23 minutes)

Pros

 * Supports concurrent installs of different releases/versions of Ruby

Cons

 * Requires significant drive space - more than what's available on the standard 2GB image
 * Might be overkill for most users

Commands
The commands should eventually be integrated into this page. Until then, they are available as part of the RPi Ruby on Rails page.

Testing Your Ruby Installation
ruby --version

Ruby 1.8.7

 * Core API
 * Standard Library - additional features that are included with Ruby 1.8.7

Ruby 1.9.3

 * Core API
 * Standard Library - additional features that are included with Ruby 1.9.3

Write and run a simple program
irb p "Hello World!" exit

Install RubyGems
(If not already installed - RubyGems is included in some Ruby distributions)

You can optionally install RubyGems, a package manager for Ruby plugins. It is a popular tool among the Ruby development community. These instructions install the most current version of RubyGems available as of this writing. These instructions also include an optional step to upgrade from this version to the latest actual release. cd ~ wget http://rubyforge.org/frs/download.php/76073/rubygems-1.8.24.tgz gunzip rubygems-1.8.24.tgz tar -xf rubygems-1.8.24.tar cd rubygems-1.8.24 sudo ruby ./setup.rb cd .. rm -fR rubygems-1.8.24 sudo gem update --system
 * 1) Download, unzip, untarball, install RubyGems, and then delete the source
 * 1) Optional - update RubyGems to a newer version