Installing Ruby on Rails and MultiRuby on Snow Leopard

Below are instructions on how to install a multi-ruby system, Ruby on Rails and everything you need to run a basic Ruby on Rails setup.

Running the RVM gem (which we show how to install) allows you to easily run multiple Ruby versions and switch seamlessly between them.

First steps:
- Checking your Architecture
Make sure that the stuff you install actually fits your current architecture. Even if you have a machine capable of 64bit it doesn’t necessarily mean that the OS you are running is 64bit. To check what your mac is running open the terminal and type:

uname -a

This should bring back something like this:
I am running this on a Macbook with i386 architecture (32 bit) so I see the following:

Darwin Dynamic50s-MacBook.local 10.2.0 Darwin Kernel Version 10.2.0: Tue Nov  3 10:37:10 PST 2009; root:xnu-1486.2.11~1/RELEASE_I386 i386

If I run the same test on a 64 bit machine instead of i386 I see x86_64

Darwin Dynamic50s-Macbook-Pro.local 10.0.0 Darwin Kernel Version 10.0.0: Tue Nov 3 10:37:34 PDT 2009; root:xnu-1456.1.25~1/RELEASE_X86_64 x86_64

Keep a note of this as you will need it later.

- Xcode
You need the latest version of xcode so download this from the apple developer site. Do not use the version off of the CD, get the latest version. Unless you are using XCode to develop for the IPhone, you only need the basic mac version.

- MySQL
If you want to use MySql then you will need to do the following:
If you have previously installed any versions of MySQL (from Macports or other) remove them. Make sure you download the correct version of MySQL for your architecture.
Download version from the MySQL site (DMG) here.
Make sure you get the right version for your platform, Also install the Prefpane (inside the DMG file), this makes it really easy to start and stop MySQL from System Preferences.

- Enable MySQL
Go to System Preferences and enable MySQL from the system preference pane. Then start it up and make sure it is running. Before you close the pref pane, make sure the start on start-up is also ticked.

Screen shot 2010 03 18 at 10.07.252 Installing Ruby on Rails and MultiRuby on Snow Leopard

- Git
If you use Git as your repository system then you will need to install it (if you don’t currently use it, you should be!). To do so go here and install it. You can also install this from macports, but I prefer to grab the most up to date version from the google code repos, and it comes packaged as a DMG.

Make sure it runs by opening a new terminal and running

git --version

And you should see something like this:

git version 1.7.0.2

If it is not there, you probably don’t have the path set correctly. Mine is located in

/usr/local/git/bin

So I have to make sure this bin directory is in my PATH. If I type:

env $PATH

into the terminal I get the following:

env: /Users/dynamic50/.rvm/rubies/ruby-1.8.7-p249/bin:/Users/dynamic50/.rvm/gems/ruby-1.8.7-p249/bin:/Users/dynamic50/.rvm/gems/ruby-1.8.7-p249%global/bin:/Users/dynamic50/.rvm/bin:/usr/local/mysql-5.1.45-osx10.6-x86_64/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin: No such file or directory

This shows that it indeed in the path, if it isn’t, simply add it by editing your .bash_profile file and reloading the terminal.

- Installing Ruby version manager
The recommended way of installing this is from source. Open up a new terminal and type:

cd $HOME/.rvm/src && git clone --depth 1 git://github.com/wayneeseguin/rvm.git && cd rvm && ./install

After install make sure you follow the instructions and add what is required to your bashrc and .bash_profile and the reload your sources (or restart the terminal).
Now install the Ruby versions you want.

rvm install 1.8.7
rvm install 1.9.1
rvm install 1.9.2

And set a default:

rvm --default 1.8.7
rvm default

Make sure that you are currently using the default. Open a terminal and type:

ruby --version

This should bring back something along the following lines:

ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10.2.0]

I am only going to do the following stuff for Ruby 1.8.7, but if you want to do it for the other Ruby versions installed, simply switch to a different version and then perform the same tasks.
- Installing the MySQL gem:
This always seems to cause a headache and is usually due to architecture flags.
This should work, feel free to write a note in the comments if you are having issues on this and I will try and help out.
For 64bit Intel architecture:

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

For 32bit Intel architecture:

sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

And thats about it! Now install any other gems required, or better still, use bundler and package them all into your application.

No Comments

RSS feed for comments on this post. TrackBack URL

No comments yet.

Leave a comment

Preview: