222

Homebrew recently deprecated homebrew/versions in favour of making versions available on homebrew/core via the new formula@version format. For example (as per this answer), you can do brew install postgresql@9.5.

Of course, this doesn't work for arbitrary versions. For instance, install cocoapods@1.1.1 turns up "Error: No formulae found in taps".

Under the old method, I could run brew versions <formula> to see available versions. How do I list available versions now?

Community
  • 1
  • 1
Phlippie Bosman
  • 5,378
  • 3
  • 26
  • 29

4 Answers4

249

You can search versions using brew search.

For example:

$ brew search postgresql
postgresql ✔      postgresql@9.4     postgresql@9.5
Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564
  • 74
    That's what I was afraid of... The program I need an old version for only has the current version available. Ah well. – Phlippie Bosman May 04 '17 at 18:45
  • 9
    This method is pretty useless for a package like `r`; it finds every package with an "r" in its name. – Ken Williams Dec 10 '20 at 18:07
  • How do I prevent `brew search` from including things like `github` when I search for `git`? – Aaron Franke Apr 01 '21 at 06:27
  • 4
    @KenWilliams @aaron See this answer for how to do an exact search for `r` or `git`: https://stackoverflow.com/questions/43538993/homebrew-list-available-versions-with-new-formulaversion-format/70491376#70491376 – wisbucky Dec 27 '21 at 03:12
  • Thanks @wisbucky, I didn't realize it could use a regex. – Ken Williams Dec 30 '21 at 01:08
67

This is an old question, but I found a "better" (for me) way to do this:

brew info --json PACKAGE_NAME | jq -r '.[].versioned_formulae[]'

For example, in the case of the package node, this will print:

$ brew info --json node | jq -r '.[].versioned_formulae[]'
node@10
node@12
node@8

You will need the program jq installed for it to drill down into the appropriate JSON, (brew install jq).

Since the above is gnarly to write/remember, I suggest setting up an alias or function in your favorite shell.

Note: This method will only work with Formulae and not Casks.

John Yeary
  • 1,112
  • 22
  • 45
Jonathan Apodaca
  • 5,458
  • 6
  • 30
  • 41
40

And in case you wanted to just look up the specific version used by a formula after finding it using search, you can get the info with:

brew info <formula|cask>

e.g. brew info postgresql@10, or brew info vlc. (Brew no longer needs to explicitly specify --cask for this command.)

And if you can't find a popular old version of a cask, you may be able to get it via homebrew-cask-versions, which is installable with brew tap homebrew/cask-versions.

qix
  • 7,228
  • 1
  • 55
  • 65
  • 1
    hello! And how do I use `homebrew-cask-versions` ? I've installed it with `brew tap homebrew/cask-versions` and now how do I proceed? – mariano-daniel Nov 12 '22 at 22:16
  • @mariano-daniel It should automatically add additional cask options to your `brew search` results. For example, using the `iterm` example in https://github.com/Homebrew/homebrew-cask-versions, the original 3 results (`iterm2` `therm` `zterm`) now adds: `iterm2-beta` `iterm2-legacy` `iterm2-nightly`. And if you run a `brew info` on any of them, you can see if it came from `homebrew-cask` or `homebrew-cask-versions`. – qix Nov 15 '22 at 13:23
7

To get the exact results without extraneous noise, you can use regex with brew search. It excludes qt-postgresql and postgrest, which would have been returned by brew search postgresql. This is especially helpful if you're searching for a short package name like r or git that would otherwise return a lot of noise.

$ brew search '/^postgresql$|^postgresql@/'

==> Formulae
postgresql          postgresql@11       postgresql@13       postgresql@9.5
postgresql@10       postgresql@12       postgresql@9.4      postgresql@9.6

Note, brew search does seem to support Extended Regex, so I couldn't use the more efficient regex below. Of course, you could use a grep pipe to accomplish the same:

$ brew search postgresql | grep -E '^postgresql(@.*)?$'

postgresql
postgresql@10
postgresql@11
postgresql@12
postgresql@13
postgresql@9.4
postgresql@9.5
postgresql@9.6
wisbucky
  • 33,218
  • 10
  • 150
  • 101