Homebrew: list available versions with new formula@version format
HomebrewHomebrew Problem Overview
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 [email protected]
.
Of course, this doesn't work for arbitrary versions. For instance, install [email protected]
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?
Homebrew Solutions
Solution 1 - Homebrew
You can search versions using brew search
.
For example:
$ brew search postgresql
postgresql ✔ postgresql@9.4 postgresql@9.5
Solution 2 - Homebrew
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.
Solution 3 - Homebrew
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
.
Solution 4 - Homebrew
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