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.
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.
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 (
local-podman). But if you tend to do this often for multiple formulas, you can probably name it more generically. To re-emphasize, it doesn’t need to be named after the formula. -
Actually create the copy of the formula at the specific version.
brewdoes 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. -
Now your formula will appear in your
brew searchto be installed the usual way.
I had an unique case though. For some reason though, the checksum in that commit of the formula was broken.
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. 😄
Installing the WRONG way
As mentioned before, I used the following command to find the first commit which switched the formula to 3.x.
Find the commit previous to this which changed the formula.
So, I found out that e2c833d326c45d9aaf4e26af6dd8b2f31564dc04 is that last update to the formula which had the 2.x
version. Now to install this.
Wtf! Frantic web search ensues.