Setting up your Mac OS X for Rails

If you want to run your Rails application on a Mac OS X environment (either production or development) or deploy it to a Mac OS X machine, this tsoosayLabs-post is maybe worth reading it. There is a lot of information around in the web, but I couldn’t find a website that covered all the little subtleties that I had to go through. So I try to list it here.

Here you can find a very comprehensive guide by Dan Benjamin for installing Ruby, Rails, Subversion, Mongrel, and MySQL on your Mac OS X: http://hivelogic.com/narrative/articles/ruby-rails-mongrel-mysql-osx
Another good source is the book you should read anyhow: “Agile Web Development with Rails” by Dave Thomas and David Heinemeier HansonAgile Web Development with Rails 2nd Edition.
Helpful Rails documentation in general be found here (http://www.rubyonrails.org/docs) and, more specific, this book here (http://www.pragmaticprogrammer.com/titles/rails/index.html).
I sticked very much to both - Dan’s online-guide and Dave and David’s book.

1. Prepare your Mac OS X
You need the XCode Developer Tools on your Mac for compiling some of the installables like ruby. If not installed, you can find it on the Mac OS X install DVD/CD, or download from Apple’s Developer Connection (http://developer.apple.com/tools/xcode/). I found it also useful to have X11 installed (in fact, required at us for using ImageMagick), which you can find the in the X11User package on the OS X CD (it’s an optional install) - so again, have your installation CD at hand. This will allow you to use GUI apps and build applications from source which you will need at some point. And don’t forget to have the sudo rights configured for your account - otherwise you get in trouble when installing. So make your account an administrator account.

2. Install MySQL
I used the MySQL-Installer for Mac OS X (http://www.mysql.org/downloads/mysql/5.0.html#macosx-dmg) - very easy and w/o complications.
For the hardcore: you can also download MySQL-sources and compile it yourself.

3. Install Ruby, Termios/Readline-Support for Ruby and Rails
Fully described in Dan’s guide, if you are willing to curl source-tar-balls, untar them using tar and then use the good old C-style configue and make for compiling your binaries from the sources.
Other than in Dan’s guide, you should use MacPorts (read the book!) for installing the packages ruby, ruby-termios and ruby-gem.
MacPorts is a FreeBSD-style package manager and can be found here: http://www.macports.org/, the MacPorts-GUI PortAuthority is here: http://www.apple.com/downloads/macosx/unix_open_source/portauthority.html). MacPorts allows you to easily migrate from one version to another. And, chances that you run into compile or install problems are low - MacPorts (successor of DarwinPorts) and Darwin-based Mac OS X have the same origins. So, on command line/terminal do the following:
$>sudo port install ruby
$>sudo port install rb-rubygems
$>sudo port install rb-termios


4. We’re gemming, gemming - like Bob Marley said
lastfm Bob MarleyJamming
Fine, fine: Now it’s about to install all the RubyGems that you need for running a basic Rails-application:
Rake, Rails, Termios, Mongrel, MySQL Native Bindings Gem (better performance).
For peeking what RubyGems to install exist on the other side: sudo gem list --remote, for seeing what you have locally installed: sudo gem list.
So, on command line/terminal:
$>sudo gem install rake --include-dependencies
$>sudo gem install rails --include-dependencies
$>sudo gem install termios --include-dependencies
$>sudo gem install mongrel --include-dependencies
$>sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql

If you plan to use your machine for deployment or only testing a deployment, you have to install the Capistrano gem. If not, do it also - it’s helpful and does no harm, even if you really never, never use capistrano - what you won’t, believe me.
$>sudo gem install capistrano --include-dependencies
If this is a machine to deploy to either for testing or for production, install the Mongrel_Cluster gem. Again, just install it, don’t think about it.
$>sudo gem install mongrel_cluster --include-dependencies

5. Basic Installation done
So far so good. The basic steps are done now. You can start now the sample app.
$>rails whatever_your_sample_app_name
$>cd whatever_your_sample_app_name
$>script/server

Lay back and see your first Rails application starting - you lucky boy/girl.
If script/server fails, try ruby script/server.

6. Next
The more savvy or impatient or ambitious might have recognized - there is no database created. We will treat this and other things like capistrano deployment, installing subversion client (assuming SVN as SCM) in one of my next posts.

e_phase | Posted in ruby on rails |

Bookmark on del.icio.us  Bookmark on del.icio.us     Bookmark on digg  Bookmark on digg

One Response

  1. dazzliod Says:

    I can’t see a time in the near future where I will have to follow these instructions (hey, I work with you guys) but this is an excellent and informative post. Long live our blog! :)

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.