How to get the version of a installed package using ocamlfind or opam?

125 views Asked by At

In my configure script, I need to check the installed version of a package <package> using ocamlfind or opam. How do I get this information?

1

There are 1 answers

0
anol On

Using ocamlfind: ocamlfind query -format %v <package>

This information is not directly available when running ocamlfind query --help, but it is available with ocamlfind query -help-format, which displays it among the other format options:

Formats for -format strings:
    ...
    %v         version
    ...

Using opam: opam info -f installed-version <package>

It returns -- when the package is not installed.

This comes from opam info --help:

  -f FIELDS, --field=FIELDS
       Only display the values of these fields. Fields can be selected
       among name, version, package, synopsis, synopsis-or-target,
       description, <field>:, installed-version, pin, source-hash,
       opam-file, all-installed-versions, available-versions,
       all-versions, repository, installed-files, vc-ref, depexts.
       Multiple fields can be separated with commas, in which case field
       titles will be printed; the raw value of any opam-file field can be
       queried by suffixing a colon character (:), e.g. --field=depopts:.