update 2011-07-26: The Install (Lion Edition) can be found here

Long story short

The following are steps we take at Hashrocket when setting up a near perfect Ruby development environment in OS X Snow Leopard1. Feel free to copy and paste the commands into your terminal.

A Word of Caution

While it is unlikely any instruction given below might damage your system, it’s always a good idea to backup everything before doing any of it, just in case. I am not responsible for anything that may result from following the instructions below. Proceed at your own risk.

Step 0:

Prerequisite OS X Apps:

Snow Leopard Samba Fix2

echo "[default]" >  ~/Library/Preferences/nsmb.conf
echo "streams=no" >> ~/Library/Preferences/nsmb.conf

Remove system gems

sudo rm -r /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
sudo gem update --system
sudo gem clean

Install homebrew

sudo mkdir /usr/local
sudo chown -R `whoami` /usr/local
curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C /usr/local

Create .bash_profile

echo '. "$HOME/.bashrc"' > ~/.bash_profile

Install MacVim

brew install macvim

Install utilities

brew install wget proctools ack ctags-exuberant markdown

Get git

brew install git

dotfiles, dev folder

mkdir ~/hashrocket
cd ~/hashrocket
git clone http://github.com/hashrocket/dotmatrix.git

ln -s ~/hashrocket/dotmatrix/.bashrc ~/
ln -s ~/hashrocket/dotmatrix/.hashrc ~/
ln -s ~/hashrocket/dotmatrix/.vim ~/
ln -s ~/hashrocket/dotmatrix/.vimrc ~/
sh ~/hashrocket/dotmatrix/bin/vimbundles.sh

Install rvm

mkdir -p ~/.rvm/src/ && \
  cd ~/.rvm/src && \
  rm -rf ./rvm/ && \
  git clone --depth 1 git://github.com/wayneeseguin/rvm.git && \
  cd rvm && \
  ./install
echo 'if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then source "$HOME/.rvm/scripts/rvm" ; fi' \
       >> ~/.bashrc.local
echo 'rvm_project_rvmrc_default=1' \
  > ~/.rvmrc # Use default gemset when leaving a .rvmrc project dir
echo '[[ -r $rvm_path/scripts/completion ]] && source $rvm_path/scripts/completion' \
       >> ~/.bashrc.local # rvm autocompletion

Install openssl

rvm package install openssl

Install the rubies to your heart’s content

rvm install ree -C --enable-shared=yes
rvm install 1.8.7 -C --enable-shared=yes
rvm install 1.9.2 -C --enable-shared=yes
rvm use 1.8.7 --default

Setup your .gemrc

echo -e '---
:benchmark: false
gem: --no-ri --no-rdoc
:update_sources: true
:bulk_threshold: 1000
:verbose: true
:sources:
- http://rubygems.org
- http://gems.github.com
:backtrace: false' > ~/.gemrc

MySQL

brew install mysql # Follow instructions

Postgresql

brew install postgresql # Follow instructions

If you get the following error:

@FATAL:  could not create shared memory segment: Cannot allocate memory@

Run this in your terminal window and try the @initdb@ command again.3

sudo sysctl -w kern.sysv.shmall=65536
sudo sysctl -w kern.sysv.shmmax=16777216

Install global gems

for x in $(rvm list strings)
do
  # Uncomment the next 4 lines to install mysql, pg, & mongrel
  # rvm use $x@global && gem install mysql --\
  #  --with-mysql-dir=/usr/local \
  #  --with-mysql-config=/usr/local/bin/mysql_config
  # rvm use $x@global && gem install mongrel pg
  rvm use $x@global && gem install open_gem ruby-debug hitch
done

RubyCocoa (for rspactor)

mkdir -p /usr/local/src
cd /usr/local/src
wget http://sourceforge.net/projects/rubycocoa/files/RubyCocoa/1.0.0/RubyCocoa-1.0.0.tar.gz/download
tar xzf RubyCocoa-1.0.0.tar.gz && rm RubyCocoa-1.0.0.tar.gz && cd RubyCocoa-1.0.0
ruby install.rb config --build-universal=yes
ruby install.rb setup
# have to sudo to install this because the installer wants to copy example stuff out of the /System dir
sudo ruby install.rb install
sudo chown -R `whoami` /usr/local # For good measure

Growl

cd ~/Downloads
wget http://growl.cachefly.net/Growl-1.2.dmg
open Growl-1.2.dmg
cd /Volumes/Growl-1.2/Extras/growlnotify/
# Don't use the install shell script
# Use the following:
mkdir -p /usr/local/bin
echo "Creating /usr/local/bin"
mkdir -p /usr/local/man/man1
echo "Creating /usr/local/man/man1"
cp growlnotify /usr/local/bin/growlnotify
cp growlnotify.1 /usr/local/man/man1/growlnotify.1

Generate a pubkey for that station

ssh-keygen -t rsa
# Add public key to your github account
  1. It may work for Leopard… I just haven’t tried it yet.

  2. More info (Thanks Alan Jones for the tip)

  3. Found this here