Jared McFarland

The musings of a 20-something engineer

Full Stack Ruby on Rails Development for Snow Leopard

This blog is gonna talk about setting up Ruby, RubyGems, SVN, Git, Rails and MySQL for Snow Leopard. There’s a few other articles that go really in depth with setting up custom server configurations for Snow Leopard, but I found them to be doing more than I need for my personal development ( here ).

In order to get started you’ll have to have Snow Leopard installed, along with XCode (which includes X11). If you don’t install XCode you’ll get an error trying to install things with MacPorts.

Disclaimer: This setup worked for me twice, once on a MBP and once on a 27” iMac i5. I can’t guarantee it’ll work for you. If you run into issues, feel free to leave a comment, but I can’t promise I’ll know the answer.

I’ve setup two different Snow Leopard computers in the past couple days to do this, and I’ve compiled some notes on what worked for me.

To start off, install MacPorts j following their instructions.

If you’re like me, you use Bash as your default shell, so add this to your ~/.profile

1
2
3
export PATH="/usr/local/bin:$PATH"
export MANPATH="/usr/local/share/man:$MANPATH"
export INFOPATH="/usr/local/share/info:$INFOPATH"

Chances are, if you’re using Snow Leopard, you’re running 64-bit apps and you have a chip that supports 64-bit architecture. If it does, you can force MacPorts to install apps with 64-bit architecture. Open up /opt/local/etc/macports/macports.conf And change the “build_arch” setting (around line 59) to x86_64.

Once that’s done, you’re ready to install Ruby.

1
sudo port install ruby

It’ll take awhile, so go grab a cup of coffee or something while you wait. Once that’s done, running which ruby should show /opt/local/bin/ruby

And running ruby -v should show ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10]

Next step is rubygems

1
sudo port install rb-rubygems

After that is SVN and Git

1
2
sudo port install subversion
sudo port install git-core +svn

Next up is MySQL. At the time of writing this, no package for Mac OS 10.6 has been released. So download the 10.5 x86_64 package from here .

Install both packages and the PrefPane (for some reason the pref pane is still 32-bit so it’ll ask you to restart System Preferences every time you use it).

In order to access MySQL from the command line, add this to your ~/.profile

1
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

Then run the following in order to refresh your shell.

1
source ~/.profile

After installing Rails, you need to install the MySQL adapter gem:

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

That particular command will tell it to instal the x86_64 version of the gem, and points it to your mysql config files.

Lastly, install Rails. This will install about 8 different gems, and take a few minutes.

1
sudo gem install rails

Afterwards, you can test this all by running:

1
2
3
4
rails testapp -d mysql
cd testapp
rake db:create:all
./script/server

And browse to http://localhost:3000 .

Bonus: If you’re using sqlite3 , then run this command to get it to install.

1
sudo gem install sqlite3-ruby

Comments