For the git checkout commands we'll want to be in /usr/local. Let's go there now:
cd /usr/localRemove old versions of ruby
brew rm -f rubySetup homebrew to find old formulas:
brew tap homebrew/versions; brew updateRun brew versions ruby and then git checkout the ruby formula we want. Here's a nice one liner to do it for you:
$(brew versions ruby | grep 1.9.3-p392 | cut -d\ -f2-)Now with the old formula in place we can install ruby 1.9.3
brew install rubyNow for each version of ruby we want to install, we need to brew unlink the formula, git checkout the version we want and brew install it:
brew unlink ruby
$(brew versions ruby | grep 2.0.0-p0 | cut -d\ -f2-)
brew install rubyTo finish the install you'll want to add $(cd $(which gem)/..;pwd) to your PATH in .zshenv or another sourced file such as .zshrc or, if you must, .bashrc. There may be a more elegant way to do this, but it works.
vim ~/.zshenv
source ~/.zshenvNote: brew cleanup deletes old versions -- don't run it!
brew switch ruby 1.9.3-p392
source ~/.zshenv
brew switch ruby 2.0.0-p0
source ~/.zshenvNote: You can run ruby -v && readlink $(which gem) to verify your ruby version and gem path.
Nothing much different here, just brew switch to the ruby version, source your env and gem install
gem install bundler foreman pg rails --no-ri --no-rdoc -f
readlink $(which bundle)
brew switch ruby 1.9.3-p392
source ~/.zshenv
gem install bundler foreman pg rails --no-ri --no-rdoc -f
readlink $(which bundle)If you want an easier way to switch versions, I hacked together this zsh function.
# ~/.zshrc
rbv () { brew switch ruby $(brew switch ruby list 2>&1 |tail -1|cut -d\ -f3-|tr -d ','|tr ' ' "\n" | grep "^$1" | head -1) && source ~/.zshenv }Now you can just run rbv 1.9.3 and it will find the latest installed version of ruby 1.9.3 and switch to it. It runs source ~/.zshenv so make sure you have the dynamic gem path in your $PATH as I mention above in the installation section.