giant robots smashing into other giant robots

Written by thoughtbot

dancroak

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

It’s been two and a half years since my last laptop. It’s neat to look back and see how much has improved since then for setting up a Ruby development environment.

Of particular note, Homebrew, RVM, and Bundler did not exist back then.

Here’s how I set up an OS X 10.7 (Lion) thoughtbot laptop in 2011.

GCC

I need GCC to help install everything else so I downloaded GCC for Lion.

We used to have to install XCode to get GCC when OS X wasn’t for developers, which was a 3-4GB download and took 10GB+ of space. Buzzkill.

However, Kenneth Reitz, one of the Readability guys, fixed this with his OS X GCC installer, which is a comparatively svelte 272MB download.

Later on, when we’re installing things using Homebrew, we’ll see warnings like:

Xcode is not installed! Builds may fail!

But, the builds will build fine.

While that’s installing, we’ll customize our environment a little.

SSH

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

ssh-keygen -t rsa

I’m kept hitting “enter” until it was done. Alternatively, I could have brought my old SSH key over but I’m not into falconry.

dotfiles

We have a standard set of configurations for vim, irb, git, zsh, and more.

I cloned the repo:

git clone git://github.com/thoughtbot/dotfiles.git

I ran the installer:

./install.sh

This sets up the appropriate symlinks (~/.vimrc, ~/.irbrc, etc.). I’ll stay up-to-date and contribute using the fork-track-update flow described in the README.

zsh

Our dotfiles assume zsh so I switched from the bash default to zsh:

chsh -s /bin/zsh

Re-map Caps Lock to Control

We’re pretty much all vim users here so it’s nice having super-quick home-row access to the Control key… and who uses Caps Lock, anyway?

System Preferences > Keyboard > Modifier Keys

git

Already installed by default, but I set the global config:

git config --global user.name "Your Name"
git config --global user.email you@example.com

Heroku accounts

I’m using Heroku for all my apps right now. However, thoughtbot’s clients and even our own apps like Trajectory are not owned by my Heroku account. So, it comes in handy to be able to switch to a different account on a project basis.

heroku plugins:install git://github.com/ddollar/heroku-accounts.git
heroku accounts:add dan  --auto
heroku accounts:add thoughtbot  --auto
heroku accounts:add client  --auto
heroku accounts:default dan

thoughtbot’s laptop script

Once GCC is downloaded and installed, I’m ready for the heavy-duty installation using our laptop script.

bash < <(curl -s https://raw.github.com/thoughtbot/laptop/master/mac)

This installs:

  • Homebrew (for managing operating system libraries)
  • Postgres (for storing relational data)
  • Redis (for storing key-value data)
  • Ack (for finding things in files)
  • Tmux (for saving project state and switching between projects)
  • ImageMagick (for cropping and resizing images)
  • RVM (for managing versions of the Ruby programming language)
  • Ruby 1.9.2 stable (for writing general-purpose code)
  • Bundler gem (for managing Ruby libraries)
  • Rails gem (for writing web applications)
  • Heroku gem (for interacting with the Heroku API)
  • Taps gem (for pushing and pulling SQL databases between environments)
  • Postgres gem (for making Ruby talk to SQL databases)

It took about 15 minutes for everything to install.

While it’s running, it copies your SSH key to the clipboard and opens your Github SSH page. Paste your SSH key so your Github account is authenticated to your machine.

Caveats

We wrote a laptop script because we help hundreds of people a year get a Ruby development environment set up at workshops and Boston Ruby hackfests. One time we set up 30 business school students’ laptops in 3 hours.

If you read our source, you’ll see it it’s very simple but more invasive than, say, the excellent Cinderella by Corey Donohoe, which uses Chef to keep your machine tidy. We’re assuming the person definitely wants a “thoughtbot laptop”.

DIY

It’s pretty easy to write a wrapper that installs Homebrew, RVM, and your favorite databases and gems so consider forking our project and writing your own script, just like you might write your own Rails template script like Suspenders.

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.