Difference between revisions of "RPi Ruby"

From eLinux.org
Jump to: navigation, search
(Next Steps: Fleshing out the Next Steps section with actual text! Moving the RubyGems instructions from an earlier section.)
m (Install Rails)
 
(18 intermediate revisions by the same user not shown)
Line 72: Line 72:
 
  cd ..
 
  cd ..
 
  rm -fR ruby-1.8.7-p358
 
  rm -fR ruby-1.8.7-p358
You can optionally install [http://rubyforge.org/projects/rubygems/ RubyGems] , a package manager for Ruby plugins.  It is a popular tool among the Ruby development community, and now's as good of a time as any...  (Assuming Ruby installed successfully!)  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, if newer.
 
# Download, unzip, untarball, install RubyGems, and then delete the source
 
cd ~
 
wget http://rubyforge.org/frs/download.php/76073/rubygems-1.8.24.tgz
 
gunzip rubygems-1.8.24.zip
 
tar -xf rubygems-1.8.24.tar
 
cd rubygems-1.8.24
 
sudo ruby ./setup.rb
 
cd ..
 
rm -fR rubygems-1.8.24
 
# Optional - update RubyGems to a newer version
 
sudo gem update --system
 
  
 
==== Ruby v1.9.x ====
 
==== Ruby v1.9.x ====
Line 91: Line 79:
 
* Newest release of Ruby
 
* Newest release of Ruby
 
* Uses 15MB of hard drive space, even with the additional tools that don't come with the other releases
 
* Uses 15MB of hard drive space, even with the additional tools that don't come with the other releases
* Install RubyGems and some popular gem add-ons (optional tools/features that you may need)
+
* Installs RubyGems and some popular gem add-ons (optional tools/features that you may need)
 +
 
 
===== Cons =====
 
===== Cons =====
 
* Requires 250MB of free space during installation - this is nearly all the available space on the standard 2GB image.
 
* 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)
 
* Installs RubyGems and some popular gem add-ons (optional tools/features that you may not need)
 
===== Commands =====
 
===== 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 innocuous 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!
+
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.
 
Compiling Ruby from the source code requires that a few other development packages are already installed.
 
  # Install development dependencies for compiling Ruby
 
  # Install development dependencies for compiling Ruby
Line 117: Line 107:
 
  # (wait 23 minutes)
 
  # (wait 23 minutes)
 
  sudo make install
 
  sudo make install
 +
# (wait 3 minutes)
 
Delete the source code (we need that space!)
 
Delete the source code (we need that space!)
 
  cd ..
 
  cd ..
Line 128: Line 119:
 
* Might be overkill for most users
 
* Might be overkill for most users
 
=== Commands ===
 
=== Commands ===
The commands will eventually be integrated into this page.  Until then, they are available as part of the [[RPi_Ruby_on_Rails|RPi Ruby on Rails]] page.
+
The commands should eventually be integrated into this page.  Until then, they are available as part of the [[RPi_Ruby_on_Rails|RPi Ruby on Rails]] page.
  
 
+
== Testing Your Ruby Installation ==
== Testing Your Installation ==
+
 
  ruby --version
 
  ruby --version
  
 
== Next Steps ==
 
== Next Steps ==
=== Check out the language reference guide ===
+
=== Check out the official Ruby language documentation ===
=== Write and run a basic program ===
+
==== Ruby 1.8.7 ====
 +
*[http://www.ruby-doc.org/core-1.8.7/ Core API]
 +
*[http://www.ruby-doc.org/stdlib-1.8.7/ Standard Library] - additional features that are included with Ruby 1.8.7
 +
==== Ruby 1.9.3 ====
 +
*[http://www.ruby-doc.org/core-1.9.3/ Core API]
 +
*[http://www.ruby-doc.org/stdlib-1.9.3/ Standard Library] - additional features that are included with Ruby 1.9.3
 +
 
 +
=== Write and run a simple program ===
 
  irb
 
  irb
 
  p "Hello World!"
 
  p "Hello World!"
 
  exit
 
  exit
 +
 
=== Install RubyGems ===
 
=== Install RubyGems ===
(if not already installed)  
+
(If not already installed - RubyGems is included in some Ruby distributions)
You can optionally install [http://rubyforge.org/projects/rubygems/ RubyGems] , a package manager for Ruby plugins.  It is a popular tool among the Ruby development community, and now's as good of a time as any...  (Assuming Ruby installed successfully!) 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, if newer.
+
 
 +
You can optionally install [http://rubyforge.org/projects/rubygems/ 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.
 
  # Download, unzip, untarball, install RubyGems, and then delete the source
 
  # Download, unzip, untarball, install RubyGems, and then delete the source
 
  cd ~
 
  cd ~
 
  wget http://rubyforge.org/frs/download.php/76073/rubygems-1.8.24.tgz
 
  wget http://rubyforge.org/frs/download.php/76073/rubygems-1.8.24.tgz
  gunzip rubygems-1.8.24.zip
+
  gunzip rubygems-1.8.24.tgz
 
  tar -xf rubygems-1.8.24.tar
 
  tar -xf rubygems-1.8.24.tar
 
  cd rubygems-1.8.24
 
  cd rubygems-1.8.24
Line 152: Line 151:
 
  cd ..
 
  cd ..
 
  rm -fR rubygems-1.8.24
 
  rm -fR rubygems-1.8.24
 +
Test your RubyGems installation
 +
# Test that RubyGems installed correctly
 +
gem --version
 +
You can update the RubyGems program to the latest version using this command:
 
  # Optional - update RubyGems to a newer version
 
  # Optional - update RubyGems to a newer version
 
  sudo gem update --system
 
  sudo gem update --system
 +
You can list the installed gems with:
 +
# List the installed gems
 +
gem list
 +
Installing and removing gems is handled by the following commands:
 +
# Install a new gem ("acts_as_list" is the name of a gem)
 +
sudo gem install acts_as_list
 +
 +
# Remove a gem ("acts_as_list" is the name of a gem)
 +
sudo gem uninstall acts_as_list
 +
Occasionally, you might want to install a specific version of a gem.  Assuming you know the version that you want to install:
 +
# Install a specific version of a gem ("acts_as_list" is the name of a gem)
 +
sudo gem install acts_as_list --version 0.1.5
 +
This command will update all of your gems:
 +
# Update all installed gems to the latest versions
 +
sudo gem update
 +
# (this may take a while - installing RDoc documentation can be CPU/RAM intensive)
 +
Running "gem update" doesn't replace your old gems with newer versions; it installs the newer version alongside the older, previously installed version.  This is a feature intended to maintain compatibility with older applications that rely on older gems, while allowing new development using the newer versions.  An application can specify which version of a gem to use.  If an application does not specify a version, the latest version will be used.
 +
 
=== Install Rails ===
 
=== Install Rails ===
 +
gem install rails
 +
# (takes about 1 hour)

Latest revision as of 14:37, 4 June 2012


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.


Installing Ruby From The Debian Repository

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:

# Install Ruby from the Debian repository
sudo apt-get install ruby

Done!

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.

# Install development dependencies for compiling Ruby
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.

# Download, unzip, and untarball the source code, and then free up some precious disk space
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

# Configure, compile, and install
cd ruby-1.8.7-p358
./configure --prefix=/usr
# (wait 3 minutes)
make
# (wait 23 minutes)
sudo make install

Delete the source code (we need that space!)

cd ..
rm -fR ruby-1.8.7-p358

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.

# Install development dependencies for compiling Ruby
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.

# Download, unzip, and untarball the source code, and then free up some precious disk space
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

# Find the correct folder name - yours might be different
ls -ld ruby-1.9.*
# Configure, compile, and install
cd ruby-1.9.3-p194
./configure --prefix=/usr
# (wait 3 minutes)
make
# (wait 23 minutes)
sudo make install
# (wait 3 minutes)

Delete the source code (we need that space!)

cd ..
rm -fR ruby-1.9.3-p194

Installing Ruby Using RVM (Ruby Version Manager)

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

Next Steps

Check out the official Ruby language documentation

Ruby 1.8.7

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.

# Download, unzip, untarball, install RubyGems, and then delete the source
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

Test your RubyGems installation

# Test that RubyGems installed correctly
gem --version

You can update the RubyGems program to the latest version using this command:

# Optional - update RubyGems to a newer version
sudo gem update --system

You can list the installed gems with:

# List the installed gems
gem list

Installing and removing gems is handled by the following commands:

# Install a new gem ("acts_as_list" is the name of a gem)
sudo gem install acts_as_list

# Remove a gem ("acts_as_list" is the name of a gem)
sudo gem uninstall acts_as_list

Occasionally, you might want to install a specific version of a gem. Assuming you know the version that you want to install:

# Install a specific version of a gem ("acts_as_list" is the name of a gem)
sudo gem install acts_as_list --version 0.1.5

This command will update all of your gems:

# Update all installed gems to the latest versions
sudo gem update
# (this may take a while - installing RDoc documentation can be CPU/RAM intensive)

Running "gem update" doesn't replace your old gems with newer versions; it installs the newer version alongside the older, previously installed version. This is a feature intended to maintain compatibility with older applications that rely on older gems, while allowing new development using the newer versions. An application can specify which version of a gem to use. If an application does not specify a version, the latest version will be used.

Install Rails

gem install rails
# (takes about 1 hour)