12 Answers
12

(I’ve re-edited my answer to give a more thorough workflow for installing/using older software versions with homebrew. Feel free to add a note if you found the old version better.)

Let’s start with the simplest case:

1) Check, whether the version is already installed (but not activated)

When homebrew installs a new formula, it puts it in a versioned directory like /usr/local/Cellar/postgresql/9.3.1. Only symbolic links to this folder are then installed globally. In principle, this makes it pretty easy to switch between two installed versions. (*)

If you have been using homebrew for longer and never removed older versions (using, for example brew cleanup), chances are that some older version of your program may still be around. If you want to simply activate that previous version, brew switch is the easiest way to do this.

(*) Please note that brew switch only works as long as all dependencies of the older version are still around. In some cases, a rebuild of the older version may become necessary. Therefore, using brew switch is mostly useful when one wants to switch between two versions not too far apart.

2) Check, whether the version is available as a tap

Especially for larger software projects, it is very probably that there is a high enough demand for several (potentially API incompatible) major versions of a certain piece of software. As of March 2012, Homebrew 0.9 provides a mechanism for this: brew tap & the homebrew versions repository.

That versions repository may include backports of older versions for several formulae. (Mostly only the large and famous ones, but of course they’ll also have several formulae for postgresql.)

Note that this has automatically tapped the homebrew/versions tap. (Check with brew tap, remove with brew untap homebrew/versions.) The following would have been equivalent:

$ brew tap homebrew/versions
$ brew install postgresql8

As long as the backported version formulae stay up-to-date, this approach is probably the best way to deal with older software.

3) Try some formula from the past

The following approaches are listed mostly for completeness. Both try to resurrect some undead formula from the brew repository. Due to changed dependencies, API changes in the formula spec or simply a change in the download URL, things may or may not work.

Since the whole formula directory is a git repository, one can install specific versions using plain git commands. However, we need to find a way to get to a commit where the old version was available.

a) historic times

Between August 2011 and October 2014, homebrew had a brew versions command, which spat out all available versions with their respective SHA hashes. As of October 2014, you have to do a brew tap homebrew/boneyard before you can use it. As the name of the tap suggests, you should probably only do this as a last resort.

Obviously, fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422 is the commit we’re interested in. As this commit is pretty old, we’ll try to downgrade the complete homebrew installation (that way, the formula API is more or less guaranteed to be valid):

You may skip the last command to keep the reference in your git repository.

One note: When checking out the older commit, you temporarily downgrade your homebrew installation. So, you should be careful as some commands in homebrew might be different to the most recent version.

You can also just checkout the formula using git checkout fa992 -- Library/Formula/postgresql.rb. When you're done, you can undo the changes to the formula using git revert HEAD Library/Formula/postgresql.rb && git checkout -- Library/Formula/postgresql.rb.
–
mipadiJan 3 '11 at 20:59

14

Note: on a fresh Homebrew install, you may need to brew update to establish its Git repo.
–
BluuMay 28 '11 at 0:57

3

I'm a brew newbie (brewbie?) and I ran the git checkout ... for a specific mysql version, but now what? I tried brew install mysql at this point, but I get Error: This is a head-only formula; install with "brew install --HEAD mysql". Then I try brew install --HEAD mysql and I get Error: No head is defined for mysql. Am I missing something obvious?
–
istrasciJan 9 '12 at 21:06

4

For update I, I had to brew unlink <formula> before running the brew install part
–
Josh DiehlAug 19 '12 at 4:42

1

For brew switch to work, you need to have the version already installed (= in the cellar) but inactive. brew versions gives you a git command which you may want to use to checkout the older version’s formula.
–
DebilskiSep 26 '13 at 11:51

Seems like the simplest, but when I copy and paste, get fatal: Not a git repository (or any of the parent directories): .git. I just cd into the directory instead (without the FORMULANAME.rb), then do the git checkout 120938
–
Ramon TayagJul 1 '12 at 12:28

I tried this, and it succeded with the message " 33 links created for /usr/local/Cellar/node/0.4.7 " , but when I run node afterwards, it fails with the message " -bash: /usr/local/bin/node: No such file or directory " . Any idea what couldlve gone wrong? Note: i downloaded 0.4.7 manually and put it in the cellar directory, because I dont know how to download anyhting but the latest node version using brew.
–
Soroush HakamiDec 22 '11 at 21:36

@Souroush Hakami you can't just put it in the folder, you have to put the compiled version in the Cellar folder.
–
aledalgrandeMar 2 '12 at 23:49

This is the only thing that worked for me. Pretty silly that a package manager requires so much futzing around just to install a prior version. Perhaps I'm spoiled by ruby RVM and bundler, but this process really needs to be streamlined and abstracted.
–
poetmountainNov 3 '13 at 2:30

When I tried to go to a previous version of Ansible, I had to unlink the formula before installing the previous version as indicated. So before doing brew install <url>, brew unlink <formulaname>. Otherwise, this is the simplest and most concise way (so far) to switch to a specific version of a formula.
–
bigsweaterJun 9 at 16:15

This was very helpful. Note, the apache foundation has reorganized the maven binaries into version (1,2,3) specific directories, so you will need to edit the maven.rb for 2.2.1 and perhaps others to fit the new structure. For example, the binary for 2.2.1 was located at: apache.org/dist/maven/maven-2/2.2.1/binaries/…. Note the "maven-2/2.2.1/" in the url.
–
Charles ForceyFeb 5 '13 at 7:22

@CharlesForcey You are correct about the maven dist repo being reorganized. I will update the answer to use brew tap to use the older maven2 formula. Thanks for the comment.
–
Cameron GoodaleFeb 6 '13 at 20:31