Downgrade Brew Package

Problem

You want to downgrade a package imported by Homebrew from version B to version A.

Solution

Packages correspond to installation script which are hosted (and versioned) on the Homebrew’s Github repository.

The list of formulas is hosted at

https://github.com/Homebrew/homebrew-core/tree/master/Formula

Clicking on the installation file for a given package (e.g. kubernetes-cli.rb for the Kubernetes command line utility) and viewing the revision history by clicking on “History”, you can find out which prior versions can be installed. If we now click on the <> icon (titled “browse the repository at this point in the history”) of the entry for the desired revision, the navigation bar will contain the root path for the given revision. Adding /Formula/<package-name>.rb to this lets us view the installation file for the given revision and pressing “Raw” gives us the URL for the desired installation file: e.g.

https://raw.githubusercontent.com/Homebrew/homebrew-core/1827ebb2fe905c931deb283f7245eaf465c7cbbf/Formula/kubernetes-cli.rb

for kubernetes-cli version 1.13.4.

We can now install the package version using brew install:

  brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/1827ebb2fe905c931deb283f7245eaf465c7cbbf/Formula/kubernetes-cli.rb

Notes

Inspired by this blog post by Ben Pickles.