Rogelio J. Samour github twitter linked in working with rails archives
Posted July 26, 2011

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:

1
2
3
4
5
6
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:

- Uninstall MacPorts!

Prerequisite OS X Apps:

- Chrome (+ vimium)
- Firefox (+ firebug, note that Selenium is not yet compatible with Firefox 5)
- Fluid.app
- Gitx
- SizeUp
- Teleport

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 issue 1

- Fix it system wide, with the following:

1
2
echo "[default]" | sudo tee /etc/nsmb.conf
echo "streams=no" | sudo tee -a /etc/nsmb.conf

Install homebrew

1
2
3
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

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

Install MacVim

1 brew install macvim

Install utilities

1 brew install wget proctools ack ctags-exuberant markdown

Install ImageMagick (optional)

1 brew install imagemagick

Get git

1 brew install git

dotfiles, dev folder

1
2
3
4
5
6
7
8
9
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

1
2
3
4
5
6
7
8
9
10
11
12
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:

1
2
3
4
5
6
7
8
9
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:

1
2
3
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

1
2
3
rvm install 1.8.7
rvm install 1.9.2
rvm use 1.9.2 --default

Mongo

1 brew install mongo # Follow instructions

Postgresql

1 brew install postgresql # Follow instructions

MySQL

1 brew install mysql # Follow instructions

Generate a pubkey for this box

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

Enjoy

1 More info

Thanks to Tom Preston-Werner for the CSS & layout and Les Hill for letting me 'borrow' his stuff.