How to install an older homebrew package


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:

Find formula

The formula filename should be composer.rb.

Open the file and click History:

Click History

Browse through the history and find the commit you want:

Browse commit history

Go to the commit, click the ellipsis next to the file, and click View file:

View file

Click Raw to open the raw file:

Click Raw

Replace the Formula

Select and copy the raw formula:

Copy code

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:



Please support this site and join our Discord!