public
Last active

Install a previous version of a formula with Homebrew

  • Download Gist
brewv
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#!/bin/bash
#
# Installs the previous version of a Homebrew formula
#
# Usage: brewv formula_name desired_version
#
# Based on http://stackoverflow.com/questions/3987683/homebrew-install-specific-version-of-formula#9832084
#
# Author: Matti Schneider <hi@mattischneider.fr> (http://mattischneider.fr)
 
versions=$(brew versions $1)
result=$(echo "$versions" | grep -m 1 $2) #-m 1 to stop as soon as possible
 
if [[ $? = 0 ]]
then
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
fi
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>'"
else
echo "$versions"
echo
echo "No version matching '$2' for '$1'"
echo "Available versions have been printed above"
exit 1
fi

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.