TL;DR: One-liner provided by Ryan Marvin:
curl https://raw.githubusercontent.com/Homebrew/homebrew-cask/<commit-hash>/Casks/<formula>.rb > $(find $(brew --repository) -name <formula>.rb) && brew reinstall <formula>
Problem
Did you know it’s possible to install an older version of a homebrew package or formula?
Previously, you would do this by installing an older formula URL:
brew install <FORMULA_URL>
However, this no longer works:
Error: Calling Installation of <FORMULA> from a GitHub commit URL is disabled! Use 'brew extract <FORMULA>' to stable tap on GitHub instead.
Solution
Now you need to replace the core or cask formula before installing:
export HOMEBREW_NO_AUTO_UPDATE=1
pbpaste > $(find $(brew --repository) -name <FORMULA>.rb)
brew install <FORMULA>
HOMEBREW_NO_AUTO_UPDATE=1
ensures the downgraded formula is not overwritten. Thanks Esteban Fallas for the tip.
Example
The example goes over how to install composer version 1.10.15
.
Prerequisites
Uninstall composer:
brew uninstall composer
Update brew:
brew update
Find the Formula
Find the formula in homebrew-core or homebrew-cask:
The formula filename should be composer.rb
.
Open the file and click History:
Browse through the history and find the commit you want:
Go to the commit, click the ellipsis next to the file, and click View file:
Click Raw to open the raw file:
Replace the Formula
Select and copy the raw formula:
Disable auto update:
export HOMEBREW_NO_AUTO_UPDATE=1
Open the local formula on your machine:
find $(brew --repository) -name composer.rb
Paste the copied formula so it replaces the local formula:
pbpaste > $(find $(brew --repository) -name composer.rb)
Install the formula:
brew install composer
Once that’s done, undo the changes to the formula:
cd $(find $(brew --repository) -name composer.rb -exec dirname {} \;) && git checkout .
Pin the formula to prevent accidental upgrade:
brew pin composer
Resources
Homebrew documentation: