Recipe 1.6. Fixing Ruby and Installing Rails on OS X 10.4 Tiger


Problem

Mac OS X 10.4 Tiger ships with a version of Ruby that doesn't work with the latest versions of Rails. You can fix this by installing the latest stable version of Ruby and its prerequisites. With Ruby up to date, you can then install Rails.

Solution

Install the latest stable version of Ruby in /usr/local on your filesystem.

Set your PATH variable to include /usr/local/bin and /usr/local/sbin. Add the following line to your ~/.bash_profile:

~$ export PATH="/usr/local/bin:/usr/local/sbin:$PATH"             

Make sure to "source" this file to ensure that the value of the PATH variable is available to your current shell.

~$ source .bash_profile             

Create the directory /usr/local/src, and cd into it. This will be a working directory where you'll download and configure a number of source files.

Install GNU Readline, which gives you command-line editing features, including history. Readline is needed for the interactive Ruby interpreter, irb, and the Rails console to work correctly.

/usr/local/src$ curl -O ftp://ftp.cwru.edu/pub/bash/readline-5.1.tar.gz /usr/local/src$ tar xzvf readline-5.1.tar.gz /usr/local/src$ cd readline-5.1             

(If you're running Panther, you'll need to execute this Perl command; otherwise skip to the next step.)

/usr/local/src/readline-5.1$ perl -i.bak -p -e \              "s/SHLIB_LIBS=.*/SHLIB_LIBS='-lSystem -lncurses -lcc_dynamic'/g" \               support/shobj-conf             

Configure Readline, specifying /usr/local as the installation directory by setting the prefix option of configure:

/usr/local/src/readline-5.1$ ./configure --prefix=/usr/local /usr/local/src/readline-5.1$ make /usr/local/src/readline-5.1$ sudo make install /usr/local/src/readline-5.1$ cd ..             

Download, and unpack the latest stable version of Ruby. Configure it to install in /usr/local, enable threads, and enable Readline support by specifying the location of the Readline:

/usr/local/src$ curl -O \                    ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.4.tar.gz /usr/local/src$ tar xzvf ruby-1.8.4.tar.gz  /usr/local/src$ cd ruby-1.8.4 /usr/local/src/ruby-1.8.4$ ./configure --prefix=/usr/local \             --enable-pthread \             --with-readline-dir=/usr/local /usr/local/src/ruby-1.8.4$ make /usr/local/src/ruby-1.8.4$ sudo make install /usr/local/src/ruby-1.8.4$ cd ..             

With Ruby installed, download, and install RubyGems:

/usr/local/src$ curl -O \             http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz /usr/local/src$ tar xzvf rubygems-0.8.11.tgz /usr/local/src$ cd rubygems-0.8.11 /usr/local/src/rubygems-0.8.11$ sudo /usr/local/bin/ruby setup.rb /usr/local/src/rubygems-0.8.11$ cd ..             

Use the gem command to install Rails:

~$ sudo gem install rails --include-dependencies             

For a faster alternative to WEBrick during development, install Mongrel:

~$ sudo gem install mongrel             

Discussion

On a typical Linux or Unix system, /usr/local is the place to install programs local to the site. Programs that you install in /usr/local are usually left alone by the system and not modified by system upgrades. Installing Ruby in /usr/local and setting your shell's PATH variable to include /usr/local/bin and /usr/local/sbin before any other bin directories (such as /usr/bin and /usr/sbin) lets you have two installations of Ruby on the same machine. This way, the existing version of Ruby and any system software that may depend on it are not affected by your local version of Ruby and vice versa.

When you type ruby, it should now invoke the version you installed in /usr/local. You can verify this with the which command, and make sure you have the most current release with ruby --version:

~$ which ruby /usr/local/bin/ruby ~$ ruby --version ruby 1.8.4 (2005-12-24) [powerpc-darwin7.9.0]

With Ruby and Rails successfully installed, you can create Rails projects anywhere on your system with the rails command:

~$ rails myProject             

Once you've created a project, you can start up WEBrick:

~/myProject$ ruby script/server             

To use the Mongrel server instead, start and stop it with the following (the -d option daemonizes Mongrel, running it in the background):

~/myProject$ mongrel_rails start -d ~/myProject$ mongrel_rails stop             

See Also

  • The GNU Readline Library, http://cnswww.cns.cwru.edu/~chet/readline/rltop.html

  • Mongrel home page, http://mongrel.rubyforge.org

  • Section 1.7"




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