brew install drush which installed the latest stable version (6.1), when I need the 5.x branch.
This GitHub issue indicates a drush 5.x package was made available for homebrew, but I'm unsure how to install it.
Homebrew install specific version of formula? - this answer on drupal.stackexchange might help you to get the overview of how specific formulas can be installed via homebrew.
Short version related to your specific question:
brew versions drush
You will see a list of commits that point to specific drush versions, e.g.,
6.1.0 git checkout a188056 Library/Formula/drush.rb 6.0.0 git checkout 1264aaf Library/Formula/drush.rb 6.0-rc4 git checkout 39b2450 Library/Formula/drush.rb 6.0-rc2 git checkout 2a61472 Library/Formula/drush.rb 6.0-beta1 git checkout 54ba68d Library/Formula/drush.rb 5.9 git checkout 81108ad Library/Formula/drush.rb 5.8 git checkout 91cb127 Library/Formula/drush.rb
Go to the base brew directory by typing
cd $( brew --prefix )
brew uninstall drush(this won't affect your settings in ~/.drush directory).
git checkout 81108ad Library/Formula/drush.rband you will have a brew formula available for this particular version.
brew install drush
drush --versionto make sure you have the correct version installed.
The standard way to install drush is via pear.
You can install a specific version using the following command:
pear channel-discover pear.drush.org pear install drush/drush-5.9.0
Available versions can be found on the Drush pear page: http://pear.drush.org/
If you have the most up-to-date version of Homebrew, you can use the
brew switch command. For example in my terminal I switched to 5.9, then back to 6.2:
KTaylor$ brew switch drush 5.9 Cleaning /usr/local/Cellar/drush/5.8 Cleaning /usr/local/Cellar/drush/5.9 Cleaning /usr/local/Cellar/drush/6.0-beta1 Cleaning /usr/local/Cellar/drush/6.0-rc2 Cleaning /usr/local/Cellar/drush/6.1.0 Cleaning /usr/local/Cellar/drush/6.2.0 2 links created for /usr/local/Cellar/drush/5.9 KTaylor$ brew switch drush 6.2.0 Cleaning /usr/local/Cellar/drush/5.8 Cleaning /usr/local/Cellar/drush/5.9 Cleaning /usr/local/Cellar/drush/6.0-beta1 Cleaning /usr/local/Cellar/drush/6.0-rc2 Cleaning /usr/local/Cellar/drush/6.1.0 Cleaning /usr/local/Cellar/drush/6.2.0 2 links created for /usr/local/Cellar/drush/6.2.0