anol
anol

Reputation: 9115

How to list current package versions in OPAM?

opam list -a lists all packages currently available at OPAM, but does not display the version number for packages which are not currently installed, as per the opam list --help output:

(...) the output format displays one package per line, and each line contains the name of the package, the installed version or -- if the package is not installed, (...)

How can I list all packages including their version numbers?

Upvotes: 5

Views: 3706

Answers (3)

Virgile
Virgile

Reputation: 10158

A refined (and quicker) version of anol's answer is to give the whole list of packages to opam show in one pass (asking opam to output both package and version field), and to process the result with sed, as apparently show outputs each field on its own line:

opam show -f package,version $(opam list -a -s) \
 | sed -e '/ *package:/N; s/ *package: \([^\n]*\)\n *version: \([^\n]*\)/\1: \2/'

Upvotes: 2

anol
anol

Reputation: 9115

This is not an ideal solution, but using camlspotter's recommandation, I manually queried each package for its version field, using the following shell loop:

for p in $(opam list -a -s); do echo "$p $(opam show -f version $p)"; done

It works, but it takes ~85 seconds to complete on my machine (querying over 1000 packages currently available).

Upvotes: 1

camlspotter
camlspotter

Reputation: 9040

Use opam info <packagename>.

I guess opam list does only prints the versions of already installed packages because of the package dependencies. Listing the latest versions of packages, for example, of not-yet-installed packages is not quite useful.

Upvotes: 6

Related Questions