StuartEllis.eu

Installing Ruby

  1. Installing Ruby on Linux
  2. Ruby on Microsoft Windows
  3. Ruby on Mac OS X

Installing Ruby itself is quick and easy, but this page also covers a few additional steps that are needed for an ideal Ruby 1.8 environment:

The installation notes for Linux were adapted from posts on Hackido and Coding in the Rain.

Installing Ruby on Linux

All of the Linux distributions provide packages for Ruby. Ubuntu and other Debian-based systems split Ruby into multiple packages, so you need to specify several packages to get the complete set. To install Ruby on Ubuntu, enter the following command:

sudo apt-get install ruby irb rdoc ruby-dev libopenssl-ruby libreadline-ruby

The Debian and Ubuntu distributions also provide packages of example code:

sudo apt-get install ruby1.8-examples

Once the package is installed, check /usr/share/doc/ruby1.8-examples/ for the example scripts.

Installing a C Compiler

Run this command to install a C compiler:

sudo apt-get install build-essential

Installing RubyGems

Download RubyGems directly from the RubyForge Web site. Vendor packages for RubyGems are always out of date, as new versions of RubyGems are released quite frequently.

wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
tar xvzf rubygems-1.3.7.tgz
cd rubygems-1.3.7
sudo ruby setup.rb

On Ubuntu and other Debian-based systems, run this command to register gem1.8 with the alias gem:

sudo update-alternatives --install /usr/bin/gem gem /usr/bin/gem1.8 1

Finally, run this command to test that everything is working as it should:

gem --version

You may delete the tar (.tgz) file and the uncompressed directory once you have run the setup script.

Install Gems To Your Home Directory: This ensures that RubyGems installs and updates packages to your home directory, leaving the system copies untouched.

Recommended: Installing Gems to Your Home Directory

Where possible, avoid installing gems into the global system. This ensures that the gems that you install are easy to identify and manage, and do not interfere with the global Ruby installation.

As of RubyGems 1.3, RubyGems will automatically install gems into the directory specified by the GEM_HOME environment variable if the system location is not accessible. You will see that directories are created within your GEM_HOME directory to store gem files. This means that RubyGems will do the right thing when managing packages, provided that you do not run the gem utility with administrative privileges.

To do this, edit the .profile file in your home directory, and add or amend it to include these lines:

export GEM_HOME=$HOME/gems
export PATH=$GEM_HOME/bin:$PATH

This takes effect the next time that you login or create a terminal window.

The presence of the bin subdirectory on your PATH enables you to use any command-line utilities that are installed with your gem packages.

Installing SQLite on Linux for Ruby

To use the default Ruby on Rails configuration and other applications that depend upon SQLite, you need to install it separately. On Ubuntu and Debian-like systems, run this command to install SQLite:

sudo apt-get install libsqlite3-dev sqlite3

Then install the Ruby driver for SQLite:

gem install sqlite3-ruby

Ruby on Microsoft Windows

To install Ruby on Windows, first go to the RubyInstaller project Website. Download both the RubyInstaller and the Development Kit. The Development Kit provides a C compiler. Ignore the One-Click Installer options, as the One-Click Installer has been superseded by the RubyInstaller.

Run the Ruby Installer, and accept the defaults. This automatically installs RubyGems. Follow the instructions to setup the Development Kit.

You need to have an archive utility installed, as Windows does not include support for the 7Zip format used to compress the Development Kit.

Enabling Ruby and RubyGems to Work with an NTLM Web Proxy

To enable your Ruby installation with work with web proxy servers that require Windows authentication (known as NTLM authentication), use rubysspi. This package includes several features to allow RubyGems and Ruby standard libraries to use such proxy servers.

If RubyGems is not able to fetch gem packages at this point, use your Web browser to download the rubysspi gem to your hard drive. Run the gem utility, specifying the full name of the downloaded package file. For example:

gem install rubysspi-1.3.1.gem

To enable RubyGems to work with NTLM proxies, simply install the gem and copy the file spa.rb from the package directory (e.g. C:\Ruby\lib\ruby\gems\1.8\gems\rubysspi-1.3.1) to the Ruby site directory, which is C:\Ruby\lib\ruby\site_ruby\1.8 for Ruby 1.8.

copy C:\Ruby\lib\ruby\gems\1.8\gems\rubysspi-1.3.1\spa.rb C:\Ruby\lib\ruby\site_ruby\1.8

RubyGems will then use remote servers as normal, transparently logging on to the default proxy server for the Windows installation with the credentials of the logged-in user. To set the default proxy server, go to Start > Control Panel > Network and Internet > Internet Options > Connections > LAN Settings.

Installing SQLite on Windows for Ruby

To use the default Ruby on Rails configuration and other applications that depend upon SQLite, you need to install it separately. Luis Lavena provides full instructions for setting up Rails and SQLite on Windows.

Alternatively, you can use Amalgalite, which provides SQLite as a Ruby library. Install the ActiveRecord adapter for Amalgalite to use Amalgalite with Ruby on Rails.

Ruby on Mac OS X

Current versions of Mac OS X include Ruby, along with Rails and supporting libraries. To install a C compiler, run the XCode Tools setup. The XCode Tools package is on the OS X Install DVD provided with current Macs, in the Optional Installs folder.