Why was a package installed?

Is there a way to query why a package was installed?

I’m mostly trying to figure out if I explicitly installed a package or not. If I didn’t install a package explicitly, I’d like to know which explicit package installed caused a package to get installed.

Try: opam remove thepackage

This will print the packages that would be removed by removing thepackage, and show why. E.g.:

$ opam remove react
The following actions will be performed:
  ⊘ remove reason      3.0.4  [uses utop]
  ⊘ remove utop        2.2.0  [uses react]
  ⊘ remove lambda-term 1.12.0 [uses react]
  ⊘ remove zed         1.6    [uses react]
  ⊘ remove lwt_react   1.1.0  [uses react]
  ⊘ remove react       1.2.1
===== ⊘ 6 =====
Do you want to continue? [Y/n] n

Idea from https://github.com/ocaml/opam/issues/573#issuecomment-24048917

1 Like

You can also do opam remove react --show-actions to see what would happen without risking clicking ‘y’ by mistake :wink:


$ opam list --roots
will give you packages that you explicitly installed.

–roots, --installed-roots
List only packages that were explicitly installed, excluding the ones installed as dependencies

$ opam list --depends-on=myPackage
should give you packages that depend on myPackage

List only packages that depend on one of (comma-separated) PACKAGES.

$ opam list --required-by=myPackage
should give you the dependencies of myPackage

List only the dependencies of (comma-separated) PACKAGES.