How do I install a specific version of a formula in homebrew? For example, postgresql-8.4.4 instead of the latest 9.0.
On the newest version of homebrew (0.9.5 as of this writing) there will be a specific recipe for the version of the homebrew keg you want to install. Example:
$ brew search mongodb
mongodb mongodb24 mongodb26
Then just do brew install mongodb26
like normal.
In the case that you had already installed the latest version, make sure to unlink the latest version and link the desired version: brew unlink mongodb && brew link mongodb26
.
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.
For versions not currently in the default brew formulas, you can easily create your own tap with the tool from https://github.com/buildtools-version-taps/homebrew-versions-tap-tool
Now that Homebrew/versions has been deprecated, Homebrew/core supports a few versions of formulae with a new naming format.
To install a specific version, e.g. postgresql 9.5 you simply run:
$ brew install postgresql@9.5
To list the available versions run a search with @:
$ brew search postgresql@
==> Searching local taps...
postgresql@10.1 ✔ postgresql@9.4 postgresql@9.5 postgresql@9.6
Based on the workflow described by @tschundeee and @Debilski’s update 1, I automated the procedure and added cleanup in this script.
Download it, put it in your path and brewv <formula_name> <wanted_version>
. For the specific OP, it would be:
cd path/to/downloaded/script/
./brewv postgresql 8.4.4
:)
Most of the other answers are obsolete by now. Unfortunately Homebrew still doesn’t have a builtin way of installing an outdated version, unless that version exists as a separate formula (e.g. python@2
, postgresql@9.4
…).
Luckily, for other formulas there’s a much easier way than the convoluted mess that used to be necessary. Here are the full instructions:
Search for the correct version in the logs:
brew log formula
# Scroll down/up with j/k or the arrow keys
# or use eg. /4\.4\.23 to search a specific version
# This syntax only works on pre-2.0 Homebrew versions
brew log --format=format:%H\ %s -F --grep=‹version› ‹formula›
This will show a list of commit hashes. Take one that is appropriate (mostly it should be pretty obvious, and usually is the most recent (i.e. top) one.
Find the URL at which the formula resides in the upstream repository:
brew info ‹formula› | grep ^From:
Fix the URL:
github.com
with raw.githubusercontent.com
blob/master
with the commit hash we found in the first step.Install the desired version by replacing master
in the previously found URL by the commit hash, e.g.:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/‹hash›/Formula/‹formula›.rb
(The last step may necessitate running brew unlink ‹formula›
before.)
If you have copied a commit hash you want to use, you can use something like this example to install that version, replacing the value and bash
with your commit hash and your desired formula.
BREW_VERSION_SHA=32353d2286f850fd965e0a48bcf692b83a6e9a41
BREW_FORMULA_NAME=bash
brew info $BREW_FORMULA_NAME \
| sed -n \
-e '/^From: /s///' \
-e 's/github.com/raw.githubusercontent.com/' \
-e 's%blob/%%' \
-e "s/master/$BREW_VERSION_SHA/p" \
| xargs brew install
This example is installing bash 4.4.23 instead of bash 5, though if you performed a brew upgrade
afterward then bash 5 would get installed over top, unless you first executed brew pin bash
. Instead to make this smoother WITHOUT pinning, you should first install the latest with brew install bash
, then brew unlink bash
, then install the older version you want per the script above, and then use brew switch bash 4.4.23
to set up the symlinks to the older version. Now a brew upgrade
shouldn't affect your version of Bash. You can brew switch bash
to get a list of the versions available to switch to.
Another way of achieving the same goal appears to be:
brew tap-new username/repo-name
# extract with a version seems to run a grep under the hood
brew extract --version='4.4.23' bash username/repo-name
brew install bash@4.4.23
# Note this "fails" when trying to grab a bottle for the package and seems to have
# some odd doubling of the version in that output, but this isn't fatal.
This creates a formula@version
in your custom tap that you can install per the above example. The downside is that you probably still need to brew unlink bash
and then brew link bash@4.4.23
in order to use your specific version of Bash or any other formula.