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.
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.
I need a public key to get access to private github repositories.
Hit enter over and over until it's done doing its thing.
Occasionally I need SSH forwarding. This adds my key to the OS X keychain. Set it and forget it.
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
We've written previously about configuring vim and configuring irb and script/console. We maintain an excellent set of configurations for vim, irb, git, zsh, and more.
Clone the repo:
git clone git://github.com/thoughtbot/dotfiles.git
Run the installer:
This sets up the appropriate symlinks (
~/.irbrc, etc.). As
thoughtbot/dotfiles 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:
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
dotfiles use zsh. Here's how to change the default Mac OS X shell to zsh:
chsh -s /bin/zsh
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:
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
gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
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
cheat (1.2.1) cucumber (0.3.0) 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)
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.
Firefox & Firebug
If you're a web developer, you need Firebug (or the new developer tools in Safari 4). Inspect is your friend.
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 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. Please add any other tips & tricks you might know of in the comments.