These notes are mostly for my own reference, but will hopefully be useful to other people too.

Get homebrew:
  • ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)" (this only works because Lion ships with a built in ruby)

Get ruby version manager (rvm) plus rails: 
  • \curl -L https://get.rvm.io | bash -s stable --rails

Install gcc42 with which to build ruby (because XCode 4.2 now uses clang):
  • brew update
  • brew tap homebrew/dupes
  • brew install autoconf automake apple-gcc42
  • brew link --overwrite apple-gcc42 (you may or may not need this line, and should probably try without the --overwrite first)
  • brew install libksba (some other library needed to by rvm to build ruby from homebrew sources)
  • rvm pkg install openssl

Set rvm to use a recent ruby version by default:
  • rvm use 1.9.3-p327 --default
  • rvm alias create default ruby-1.9.3-p327

Install postgresql:
  • brew install postgresql
  • initdb /usr/local/var/postgres -E utf8
Get postgresql to start automatically login with:
  • mkdir -p ~/Library/LaunchAgents
  • cp /usr/local/Cellar/postgresql/9.1.5/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
  • launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or start manually with:
  pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
And stop with:
  pg_ctl -D /usr/local/var/postgres stop -s -m fast