Recipe 1.5. Installing Rails


Problem

You want to download and install Ruby on Rails on Linux or Windows.

Solution

Before you can install Rails, you must have a working build environment and install Ruby itself. Ruby comes with most recent Linux distributions, but you should check to make sure you have a version that's compatible with Rails: 1.8.5, 1.8.4, and 1.8.2 work; 1.8.3 does not. Here's how to check your Ruby version:

$ which ruby /usr/local/bin/ruby

$ ruby -v ruby 1.8.4 (2005-10-29) [i486-linux]

If you don't have Ruby installed, you can either install it using your distribution's package manager or download and install it from source. For a source install, get the latest stable version of Ruby from http://rubyforge.org/projects/ruby. Unpack the archive into a convenient place, like /usr/local/src.

$ cd /usr/local/src/ruby-1.8.4 ./configure make sudo make install

To install Ruby on a Debian system, use Advanced Package Tool (APT) to download a precompiled binary package from the Debian package repository. Start by updating APT's package cache, then install the Ruby 1.8 package. You'll also need several other packages to get the full functionality of your Ruby development environment (e.g., libreadline is required for Readline support in irb).

$ apt-get update             

$ sudo apt-get install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 \ irb1.8 libreadline-ruby1.8 libruby1.8             

Once you've made sure you have a "good" version of Ruby on your system, proceed to install RubyGems. You can get the latest version of RubyGems from the RubyForge project page: http://rubyforge.org/projects/rubygems. Download the source code into /usr/local/src or another convenient location. Move into the source directory, and run the setup.rb script with Ruby. Note that the filenames shown here are current as of this writing, but you should use the latest version.

$ tar xzvf rubygems-0.9.0.tgz $ cd rubygems-0.9.0 $ sudo ruby setup.rb             

Once you have RubyGems installed, you can install Rails:

$ sudo gem install rails --include-dependencies             

If you're a Windows user, the first step toward getting Rails installed on Windows is (again) to install Ruby. The easiest way to do this is with the One-Click Installer for Windows. The latest stable version can be obtained at the RubyForge project page: http://rubyforge.org/projects/rubyinstaller. Download, and launch the One-Click Installer executable.

The One-Click Installer includes RubyGems, which you can then use to install the Rails libraries. Open a command prompt, and type the following to install Rails:

C:\>gem install rails --include-dependencies             

You can verify that Rails is installed and in your executable path with the following command (your Rails version will likely be higher than 1.0.0):

C:\>rails -v Rails 1.0.0

Discussion

Although you can download and install Rails from source or as a precompiled package, it makes a lot of sense to let RubyGems handle the task for you. It is likely that you're going to find other gems that you'll want to use with Rails, and RubyGems will make sure dependencies are satisfied as you install or upgrade gems down the line.

With Rails successfully installed, you'll have the rails command available within your environment; with it you can create new Rails applications. Running the following command displays the command-line options:

$ rails --help             

The solution also leaves you with many common command-line tools that are named by their version number. To make these tools a little easier to invoke, you can create a series of symbolic links to them. For example:

$ sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby  $ sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri  $ sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc  $ sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb             

See Also

  • Section 1.7"

  • Section 1.8"

  • Section 1.9"

  • Section 2.8"




Rails Cookbook
Rails Cookbook (Cookbooks (OReilly))
ISBN: 0596527314
EAN: 2147483647
Year: 2007
Pages: 250
Authors: Rob Orsini

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net