Skip to content

Instantly share code, notes, and snippets.

Created July 9, 2012 14:05
  • Star 17 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Install a previous version of a formula with Homebrew
# Installs the previous version of a Homebrew formula
# Usage: brewv formula_name desired_version
# Based on
# Author: Matti Schneider <> (
versions=$(brew versions $1)
result=$(echo "$versions" | grep -m 1 $2) #-m 1 to stop as soon as possible
if [[ $? = 0 ]]
commit=$(echo $result | cut -d ' ' -f 4)
formula=$(echo $result | cut -d ' ' -f 5)
cd /usr/local
if [[ -e $formula ]]
then brew unlink $1 # will fail if not already installed, hence the check above
git checkout $commit $formula &&
brew install $1 &&
git reset HEAD $formula &&
git checkout -- $formula
cd - > /dev/null
echo "$1 $2 installed."
echo "You can now switch versions with 'brew switch $1 <version>'"
echo "$versions"
echo "No version matching '$2' for '$1'"
echo "Available versions have been printed above"
exit 1
Copy link

Thanks :-)

Copy link

Ndpnt commented Oct 31, 2013

That's so awesome.

Copy link

sciulli commented Jan 15, 2014

Great! Thank you!

Copy link

Very helpful!

Copy link

finally - tx!


as of Oct 2014 "brew versions" is no longer part of homebrew. You need to tap homebrew/boneyard before being able to use the script above:

brew tap homebrew/boneyard  

this puts the command "brew versions" back in your tool set

Copy link

benlk commented May 31, 2017

As of Brew version 1.11.12, the boneyard is deprecated:

Copy link

doekman commented Sep 9, 2017

This all doesn't seem to be working anymore.

What worked for me: run brew info python3 to see what other versions of python3 have been installed (3.5.2_3 was listed), and then brew switch python3 3.5.2_3 to switch to the old version, and brew pin python3 to prevent upgrading.

Not sure how this works if you've never had older versions installed...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment