update: [2011-08-23] minor updates

update: [2011-11-05] I have automated this blog post into a shell script. Check it out here

TL;DR

  • Copy & paste the following into a Terminal window:
test -f /tmp/the_install.sh && rm /tmp/the_install.sh
curl -s\
  https://raw.github.com/gist/1341873/60ccc411faadf1194941d7b65347ec09b10adac2/the_install.sh \
  -o /tmp/the_install.sh
chmod 0700 /tmp/the_install.sh
. /tmp/the_install.sh

The saga continues

So this is the follow-up post to The Install - Snow Leopard Edition which helped you, the Ruby developer, set up a near-perfect development environment in Mac OS X. Only this time it’s on Apple’s latest version of Mac OS X, 10.7 (Lion). Again, feel free to copy and paste the commands into your terminal.

Take-away

This post walks you through setting up a very sustainable Ruby development environment on your Mac. You’ll be able to write Ruby on Rails apps along with anything else that uses Ruby. e.g. Sinatra Padrino Merb et al. It is also the setup we use everyday at Hashrocket

A Word of Caution

As usual, while it is unlikely any instruction given below might damage your system, it’s always a good idea to back up 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:

Install Xcode

You need to install Xcode for homebrew to compile code from source. It’s free in the Mac App Store! Xcode

OS X Named Streams issue1

  • Fix it system wide, with the following:
echo "[default]" | sudo tee /etc/nsmb.conf
echo "streams=no" | sudo tee -a /etc/nsmb.conf

Install homebrew

sudo mkdir /usr/local
sudo chown -R `whoami` /usr/local
curl -L https://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

Install ImageMagick (optional)

brew install imagemagick

Get git

brew install git

dotfiles, dev folder

mkdir ~/hashrocket
cd ~/hashrocket
git clone https://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

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

echo 'if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then source "$HOME/.rvm/scripts/rvm" ; fi' \
       >> ~/.bashrc.local

echo -e "export rvm_project_rvmrc_default=1
export rvm_install_on_use_flag=1
export rvm_project_rvmrc=1
export rvm_path='$HOME/.rvm'" > ~/.rvmrc

echo '[[ -r $rvm_path/scripts/completion ]] && source $rvm_path/scripts/completion' \
       >> ~/.bashrc.local # rvm autocompletion

Create your .gemrc by copying & pasting the following in your terminal:

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

Setup your global gems

A neat feature of rvm is defining the gems every rvm-controlled ruby will install on its global gemset. More here

Simply add your desired gems to the file: ~/.rvm/gemsets/global.gems like so:

rake -v0.9.2
hitch
dirty

Now each time you rvm install a ruby version, you’ll have hitch, dirty and rake version 0.9.2!

Install the rubies to your heart’s content

rvm install 1.8.7
rvm install 1.9.2
rvm use 1.9.2 --default

Mongo

brew install mongo # Follow instructions

Postgresql

brew install postgresql # Follow instructions

MySQL

brew install mysql # Follow instructions

Generate a pubkey for this box

ssh-keygen -t rsa
# Add public key to your github account

Enjoy