Photo by Anshu A on Unsplash

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

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

1. Clone the homebrew core repo and change directory to the repo- git clone 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<commit-Hash>/Formula/<package_name>.rbExample:brew install

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.




Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store