giant robots smashing into other giant robots

Written by thoughtbot

dancroak

2009 Rubyist’s guide to a Mac OS X development environment

My hard drive kicked the bucket recently. From scratch, here’s how I quickly got my Ruby web development environment into ship-shape form The Thoughtbot Way.

Many of these instructions are specific to Mac OS X 10.5 (Leopard). Some of them are opinionated (Vim over Textmate). Pick-and-choose what you need but this is everything that I use happily day-to-day right now.

I chose the quickest, easiest approach to installing everything. I’m not an operating system whiz, I just want a fun, powerful, working environment for developing Rails apps.

Obviously, the community moves fast so this won’t be current for long. I give 75% of it a shelf-life of a year.

Git

Simple. Download the installer and run it.

Lots of important gems we use in Rails apps are on github so let’s add it to our gem sources:

sudo gem source -a http://gems.github.com

Maybe the best part about git is its branching capabilities. One particularly awesome gem that makes branching easier is:

sudo gem install webmat-git_remote_branch

That gets you stuff like:

grb create branch_name [origin_server]

Create a new local branch as well as a corresponding remote branch based on the branch you currently have checked out. Track the new remote branch. Checkout the new branch.

SSH

Public key

I need a public key to get access to private github repositories.

ssh-keygen

Hit “enter” over and over until it’s done doing its thing.

Forwarding

Occasionally I need SSH forwarding. This adds my key to the OS X keychain. Set it and forget it.

/usr/bin/ssh-add -K

Aliases

You’ve got a few servers. Open up ~/.ssh/config and create some aliases for servers you want to be able to quickly ssh into:

Host nytimes_staging
  HostName staging.nytimes.com
  User developer

Host nytimes_production
  HostName nytimes.com
  User developer

jferris/config_files

We’ve written previously about configuring vim and configuring irb and script/console. The prodigious Joe Ferris maintains an excellent set of configurations for vim, irb, git, zsh, and more.

Clone the repo:

git clone git://github.com/jferris/config_files.git

Run the installer:

./install.sh

This sets up the appropriate symlinks (~/.vimrc, ~/.irbrc, etc.). As jferris/config_files is improved, just keep pulling the repo. If you want to make changes, fork the repo (and send us pull requests).

Go the extra mile and get ack, a fast tool for searching through files:

curl http://ack.googlecode.com/svn/tags/latest/ack > ~/bin/ack && chmod 0755 ~/bin/ack

Note that you’ll need the ~/bin directory for that to work:

mkdir ~/bin

One reason to get ack is that when you’re working in your Rails app, move your cursor over a variable or method name, type Shift-K. That will search in your project, using ack, for that variable or method name. This is part of config_files.

I really have no preference between bash and zsh. However, Joe’s config_files are awesome and they use zsh, so zsh it is!

Here’s how to change the default Mac OS X shell to zsh:

chsh -s /bin/zsh

Vim

I use MacVim. Download the installer and run it. It’s nice to have the mvim command from your shell, so copy it from wherever your downloaded MacVim to into a place where you keep scripts. I use ~/bin:

cp ~/Downloads/MacVim-7_2-stable-1_2/mvim ~/bin

Joe’s config files include lots of helpers and by default give you the popular Vibrant Ink theme for syntax highlighting.

Here’s what it looks like when working with the code from our Twitter follower contest.

XCode Tools

It’s generally good to have the XCode tools installed if you’re doing serious programming on Mac OS X. You will explicitly need it if you want to use MySQL with Ruby. The mysql gem needs to be compiled and won’t work without it. Pop in your “Mac OS X Install Disc 1” and run the XCodeTools installer:

MySQL

First, download the package for OS X 10.5×86 32 bit.

Run the installer.

Install the MySQL gem so you can use MySQL with versions of Rails >= 2.0.

sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Rubygems

The version of Rubygems that comes with Leopard is out of date. Update it.

sudo gem install rubygems-update
sudo update_rubygems

Here’s a buffet of gems you’re likely to use. sudo gem install any that look interesting:

cheat (1.2.1)
cucumber (0.3.0)
dancroak-twitter-search (0.5.6)
faker (0.3.1)
geokit (1.3.0)
giraffesoft-timeline_fu (0.1.1)
github (0.1.1)
heroku (0.6.1)
json (1.1.6)
mislav-hanna (0.1.7)
nokogiri (1.2.2)
passenger (2.1.2)
rack (0.9.1)
rails (2.3.2)
railsmachine (1.0.5)
RedCloth (3.0.4)
redgreen (1.2.2)
reek (1.1.3)
rest-client (1.0.1)
right_aws (1.10.0)
right_http_connection (1.2.4)
rr (0.7.1)
rspec (1.2.0)
sinatra (0.9.1.1)
technicalpickles-le-git (0.2.0)
thoughtbot-factory_girl (1.2.0)
thoughtbot-paperclip (2.2.7)
thoughtbot-shoulda (2.10.1)
webmat-git_remote_branch (0.3.0)
webrat (0.4.3)
wirble (0.1.2)

Capistrano

We usually use the following tasks to deploy:

cap staging deploy
cap production deploy

That comes from the capistrano-ext gem so let’s get that and the latest version of Capistrano:

sudo gem install capistrano
sudo gem install capistrano-ext

ImageMagick

We use Paperclip for file uploads in Rails apps. It requires Imagemagick, which is much less painful to install than RMagick.

Download and unpack this tarball.

Follow these instructions.

Quicksilver

As programmers, we care about not breaking our flow by context switching. That includes switching from app-to-app, or digging through bookmarks. Here’s what I want:

  • Apple+Space+”Hop”+Enter. Bam Hoptoad opens.
  • Apple+Space+”Gith”+Enter. Bam Github opens.

Download Quicksilver and change the mappings to be Apple+Space for Quicksilver and Option+Space for Spotlight (which I find I use much less often), so it gets the key that’s a little smaller and further away.

Fluid

This time around, I’m creating a Fluid app for everything I need, particularly because of how well it plays with Quicksilver. Download Fluid. (free)

Now we create the Fluid apps:

Pivotal Tracker


Now, the GHRL stack. (Github, Hoptoad, RPM, Lighthouse, pronounced “girl”, of course)

Github

Rails is on it. Many important Rubygems are there. When I’m looking for third-party code, I look here first.

Hoptoad

Ride the toad.

RPM

Fantastic monitoring of application performance. See Tuning the Toad for a real-world example of improving application performance with RPM.

Lighthouse

Great for managing tickets on open source projects, not bad at managing issues in a web app project.

gems.local

I have local RDoc for all my installed Rubygems. Follow Jason Seifer’s instructions, then create a Fluid app for it:

Here’s what Paperclip’s RDoc looks like: (check out that nice search for methods!)

Rails

I like Rails API for Rails documentation right now.

Firefox & Firebug

If you’re a web developer, you need Firebug (or the new developer tools in Safari 4). “Inspect” is your friend.

Sphinx

Sphinx is a dependency on a couple of projects I’ve seen recently. It seems to be the preferred full-text solution for Rails developers these days. Install it if you need it:

curl -O http://sphinxsearch.com/downloads/sphinx-0.9.8-rc2.tar.gz
tar zxvf sphinx-0.9.8-rc2.tar.gz
cd sphinx-0.9.8-rc2
./configure
make
sudo make install

S3 Hub

S3 Hub is a desktop application for managing your Amazon S3 buckets. It’s really clean and easy to use.

Go forth & conquer!

This will more than get you off the ground for Ruby web development on a Mac OS X machine. Please add any other tips & tricks you might know of in the comments.