How do I install a specific version of a formula in homebrew? For example, postgresql-8.4.4 instead of the latest 9.0.
The problem with homebrew/versions
is that someone has to have that specific version of software listed in the repository for you to be able to use it. Also, since brew versions
is no longer supported, another solution is required. For solutions that indicate using brew switch
, this will only work if you haven't done a brew cleanup
since the version needs to exist on your computer.
I had a problem with wanting to install a specific older version of docker-machine
which wasn't listed in homebrew/versions
. I solved this using the below, which should also work for any brew installed software. The example below will use docker-machine
as the package I want to downgrade from version 0.5.0 to 0.4.1.
Go to your homebrew Formula
directory.
You can determine this by running brew info [any package name]
.
For example, brew info docker-machine
gives me a line that shows me
a path - /usr/local/Cellar/docker-machine/0.5.0
. This tells me that on my machine, homebrew is installed at /usr/local
and my Formula
directory is located by default at /usr/local/Library/Formula
Locate the specific formula file (.rb) for your package.
Since I want to downgrade docker-machine
, I can see a docker-machine.rb
file.
Get the version history for this formula file .
Enter git log docker-machine.rb
. This will list out the complete commit history for this file. You will see output like this:
...more commit 20c7abc13d2edd67c8c1d30c407bd5e31229cacc Author: BrewTestBot Date: Thu Nov 5 16:14:18 2015 +0000 docker-machine: update 0.5.0 bottle. commit 8f615708184884e501bf5c16482c95eff6aea637 Author: Vincent Lesierse Date: Tue Oct 27 22:25:30 2015 +0100 docker-machine 0.5.0 Updated docker-machine to 0.5.0 Closes #45403. Signed-off-by: Dominyk Tiller commit 5970e1af9b13dcbeffd281ae57c9ab90316ba423 Author: BrewTestBot Date: Mon Sep 21 14:04:04 2015 +0100 docker-machine: update 0.4.1 bottle. commit 18fcbd36d22fa0c19406d699308fafb44e4c8dcd Author: BrewTestBot Date: Sun Aug 16 09:05:56 2015 +0100 docker-machine: update 0.4.1 bottle. ...more
The tricky part is to find the latest commit for the specific version you want. In the above, I can tell the latest 0.4.1 version was committed with this commit tag : commit 5970e1af9b13dcbeffd281ae57c9ab90316ba423
. The commits above this point start using version 0.5.0 (git log entries are listed from latest to earliest date).
Get a previous version of the formula file. Using the commit tag from step #3 (you can use the first 6 chars), you can get an older version of the formula file using the following:
git checkout 5970e1 docker-machine.rb
Uninstall your current package version.
Just run the normal brew commands to uninstall the current version of your package.
Ex. brew uninstall docker-machine
Install the older package version
Now, you can just run the normal brew install command and it will install the formula that you have checkout out.
Ex. brew install docker-machine
You may need to re-link by using the brew link docker-machine
if necessary.
If at any time you want to revert back to the latest version of a specific package, go into the Formula directory and issue the following commands on your formula file (.rb)
git reset HEAD docker-machine.rb
git checkout -- docker-machine.rb
Then you can brew uninstall docker-machine
and brew install docker-machine
to get the latest version and keep it that way going forward.