Tuesday, May 17, 2011

Installing Ruby, Rubygems, Rails on Mac OS X 10.5 (Leopard)

let’s get started. Unlike previous versions of Mac OS X, Leopard has everything you’ll need to compile Ruby. You don’t need to install any anything else. Take these commands and type or paste them into Terminal:


Paths
Don’t skip this step!

The path is actually an environment variable, set by a special file that’s automatically executed when you open a new Terminal window.

We need to make sure that our path is set to look for files in /usr/local (the place where we’ll be installing the tools) before looking anywhere else. This is important.

To see if the path has been set properly, we can check the contents of the .profile file (the special file hidden in our home folder) for a PATH line using a text editor(I am using TextWrangler ...).

edit ~/.profile
This will open the file if it already exists, or open a blank file if it doesn’t. Add the following line at the very end of the file:

export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
Now save and close the file.

It doesn’t matter how many other lines there are in the file, or what they say or do. Just make sure that this line comes last and you should be fine.

To make sure the changes are picked up correctly, we now need to execute the file with the following command:

. ~/.profile
It’s likely there will be no response from the shell here, just the prompt, but that’s OK, the changes have been picked up and we’re ready to move on.

You can also close your Terminal and open a new one instead if you’d like.

Now :
Go to root and move to path
/usr/local/bin

Download

We’re going to create a folder to contain the files we’re about to download and compile. If you want, you can delete this folder when you’re done, but keeping it around makes it easier to re-install (or uninstall) these apps later.

Make the new folder:

mkdir ~/src cd ~/src

Download Ruby and Rubygems:

curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p174.tar.gz curl -O http://files.rubyforge.vm.bytemark.co.uk/rubygems/rubygems-1.3.5.tgz

Compile and Install

First, Ruby:

tar xzvf ruby-1.8.7-p174.tar.gz cd ruby-1.8.7-p174 ./configure --enable-shared --enable-pthread CFLAGS=-D_XOPEN_SOURCE=1 make sudo make install cd ..

To verify that Ruby is installed and in your path, just type:

which ruby

You should see:

/usr/local/bin/ruby

If you do, this means you now have a super-fast, 64-bit version of Ruby ready to go. If you saw something different, you haven’t set your path correctly. Go back and try again.

Compile and install RubyGems:

tar xzvf rubygems-1.3.5.tgz cd rubygems-1.3.5 sudo /usr/local/bin/ruby setup.rb cd ..

Install Rails:

sudo gem install rails

sudo gem install rails

To start with, gem might complain that bundler requires a higher version. Something like this might happen, when you run “sudo gem install rails”:

ERROR:  Error installing bundler:
bundler requires RubyGems version >= 1.3.6
ERROR: Error installing bundler: bundler requires RubyGems version >= 1.3.6


If you run into that, you need to ask gem to update itself:

sudo gem update --system

Then rails’ installation should work.

If you use MySQL, you can now install the MySQL gem. You’ll need to know the location of your MySQL installation, which is typically/usr/local/mysql. Install the gem like this:

sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql

Congratulations, you now have a custom-built Ruby, RubyGems, and Rails configuration.





No comments:

Post a Comment