Installing a specific version of a Homebrew Formula
From time to time, I have felt the need to install a specific version of a Homebrew formula. Like the other day, I was investigating whether a particular problem I was facing with Podman was because of a version bump from 2.x to 3.x.
At some point in the past, a way around it was to find the formula file at a particular commit of the Homebrew tap, and
directly install it via brew install $URL
.
That is no longer supported, for good reason. But the tip provided is pretty terse.
I thought I will just jot down the steps I took to do this the recommended way.
Finding the right version of the formula
First, let us find the last 2.x version of the formula I am interested in podman
.
Step into the right repo for the Formula.
$ brew tapinfo homebrew/core
homebrew/core: 2 commands, 5786 formulae
/usr/local/Homebrew/Library/Taps/homebrew/homebrewcore (6,417 files, 487.8MB) From:
https://github.com/Homebrew/homebrewcore
$ cd /usr/local/Homebrew/Library/Taps/homebrew/homebrewcore
I am interested in the last 2.x version. I used the following command to find the first commit which switched the formula to 3.x.
$ git log p G url.*podman  Formula/podman.rbgrep e ^commit e https://github.com/containers/podman/
commit 8070a9ba0b21a0285890544c88f0479a922de809
 url "https://github.com/containers/podman/archive/v3.3.0.tar.gz"
+ url "https://github.com/containers/podman/archive/v3.3.1.tar.gz"
...
...
commit 623626510d622e64044d1d656e96386cda5cc5b9
 url "https://github.com/containers/podman/archive/v2.2.1.tar.gz"
+ url "https://github.com/containers/podman/archive/v3.0.0.tar.gz"
^C
Ok. So 2.2.1
is the version of the formula I am interested in.
Installing the RIGHT way

Create a local tap for storing the formula.
I have made it formula specific (
localpodman
). But if you tend to do this often for multiple formulas, you can probably name it more generically. To reemphasize, it doesn’t need to be named after the formula.# Create a local tap for storing the formula $ brew tapnew $USER/localpodman

Actually create the copy of the formula at the specific version.
brew
does all the hard work for you! Look at how it automatically found out the last git commit of the formula when the formula version was what you wanted.$ brew extract version=2.2.1 podman $USER/localpodman ==> Searching repository history ==> Writing formula for podman from revision e2c833d to: /usr/local/Homebrew/Library/Taps/sandipb/homebrewlocalpodman/Formula/podman@2.2.1.rb

Now your formula will appear in your
brew search
to be installed the usual way.$ brew search /podman/ ==> Formulae podman sandipb/localpodman/podman@2.2.1 If you meant "podman" specifically: It was migrated from homebrew/cask to homebrew/core. $ HOMEBREW_NO_AUTO_UPDATE=1 brew install sandipb/localpodman/podman@2.2.1
I had an unique case though. For some reason though, the checksum in that commit of the formula was broken.
$ HOMEBREW_NO_AUTO_UPDATE=1 brew install sandipb/localpodman/podman@2.2.1
...
Error: SHA256 mismatch
Expected: bd86b181251e2308cb52f18410fb52d89df7f130cecf0298bbf9a848fe7daf60
Actual: 3212bad60d945c1169b27da03959f36d92d1d8964645c701a5a82a89118e96d1
I found out the actual checksum from the official repository, edited the formula to update it and then it installed properly. Perhaps the change in checksum was worth an investigation. It was too late in the night to do that. 😄
$ curl Ls https://github.com/containers/podman/archive/refs/tags/v2.2.1.tar.gz  sha256sum
3212bad60d945c1169b27da03959f36d92d1d8964645c701a5a82a89118e96d1 
$ brew edit podman@2.2.1
# ... changed checksum of archive
$ HOMEBREW_NO_AUTO_UPDATE=1 brew install podman@2.2.1
SUCCESS!
Installing the WRONG way
As mentioned before, I used the following command to find the first commit which switched the formula to 3.x.
$ git log p G url.*podman  Formula/podman.rbgrep e ^commit e https://github.com/containers/podman/
commit 8070a9ba0b21a0285890544c88f0479a922de809
 url "https://github.com/containers/podman/archive/v3.3.0.tar.gz"
+ url "https://github.com/containers/podman/archive/v3.3.1.tar.gz"
...
...
commit 623626510d622e64044d1d656e96386cda5cc5b9
 url "https://github.com/containers/podman/archive/v2.2.1.tar.gz"
+ url "https://github.com/containers/podman/archive/v3.0.0.tar.gz"
^C
Find the commit previous to this which changed the formula.
$ git log n 1 623626510d622e64044d1d656e96386cda5cc5b9^  Formula/podman.rb
commit e2c833d326c45d9aaf4e26af6dd8b2f31564dc04
Author: Rylan Polster <rslpolster@gmail.com>
Date: Wed Feb 3 00:13:48 2021 0500
formulae: use new bottle syntax
So, I found out that e2c833d326c45d9aaf4e26af6dd8b2f31564dc04
is that last update to the formula which had the 2.x
version. Now to install this.
$ FORMULA_URL="https://raw.githubusercontent.com/Homebrew/homebrewcore/e2c833d326c45d9aaf4e26af6dd8b2f31564dc04/Formula/podman.rb"
$ HOMEBREW_NO_AUTO_UPDATE=1 brew install $FORMULA_URL
Traceback (most recent call last):
9: from /usr/local/Homebrew/Library/Homebrew/brew.rb:129:in `<main>'
8: from /usr/local/Homebrew/Library/Homebrew/cmd/install.rb:131:in `install'
7: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:308:in `parse'
6: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:629:in `formulae'
5: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:629:in `map'
4: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:633:in `block in formulae'
3: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:414:in `factory'
2: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:180:in `get_formula'
1: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:185:in `klass'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:277:in `load_file': Invalid usage: Installation of podman from a GitHub commit URL is unsupported! `brew extract podman` to a stable tap on GitHub instead. (UsageError)
Wtf! Frantic web search ensues.