Photo by Anshu A on Unsplash

How to install a specific version of any homebrew package (haproxy)

Siva
2 min readFeb 6, 2020

--

When you try to install a package using brew install <package_name> brew installs a latest version the package based on the time you last installed/updated the homebrew in your machine.

To install an older version, sometimes the command brew install <package_name@version> will work. It will only work if you have previously installed that version or deleted recently.

Approach 1: Using brew extract

The docs suggests using brew extract command to install an older version. The syntax goes

brew extract --version='version_no' <package_name> <tap_name>Example: brew extract --version='1.9' haproxy homebrew/core

Unfortunately, this did not work for me giving the error message but I think it has worked for other people.

Error: Cannot extract formula to homebrew/core

Approach 2: Using brew install

This approach involved me to looking at the git history of the package formulae at https://github.com/Homebrew/homebrew-core/

1. Clone the homebrew core repo and change directory to the repo- git clone https://github.com/Homebrew/homebrew-core.git- cd homebrew-core2. Log the git history of the package formulae in the repo and grep for the desired version- git log --oneline Formula/<package_name>.rb | grep <version>Example: git log --oneline Formula/haproxy.rb | grep '1.8.3

Note: The reason for cloning is because github UI kept failing to show the history

Sample output of git commit history.

f8ddcd1bd7 haproxy: update 1.8.3 bottle.
0a5882efa3 haproxy 1.8.3

Looking at the commit history tells me that the code at commit 0a5882efa3 is at the version I need (1.8.3). Copy the commitHash

Now run this command in your terminal

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/<commit-Hash>/Formula/<package_name>.rbExample:brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/0a5882efa3/Formula/haproxy.rb

This installs the version of the formula at that specific commit. You can verify that by checking the version.

Feel free to comment if anything seems wrong and I will update the article. Hopefully I am saving a couple of hours of digging for someone.

Cheers.

--

--