Why does opam install need to downgrade packages?

Hi everyone,

Whenever I try to install a new library/package it wants to downgrade or remove lots of packages.

This causes a lot of conflicts, and makes it difficult to install/update new libraries, or use old libraries that are dependent on old libraries.

Like in this case I want to install ollvm and it wants to downgrade menhir and other libraries. Why?

Instead of downgrading my installed libraries, why doesn’t opam use a separate folder, to install the required menhir version for the ollvm library, and link to that version?

$ opam install ollvm                                                                                                                                                         [01:08:11] 130 ↵
The following actions will be performed:
=== remove 2 packages
  ⊘ coq-lsp         0.2.4+8.20           [conflicts with menhir]
  ⊘ menhirCST       20250912             [conflicts with menhir]
=== downgrade 3 packages
  ↘ menhir          20250912 to 20211012 [required by ollvm]
  ↘ menhirLib       20250912 to 20211012 [required by menhir]
  ↘ menhirSdk       20250912 to 20211012 [required by menhir]
=== recompile 2 packages
  ↻ ocamlformat     0.27.0               [uses ocamlformat-lib]
  ↻ ocamlformat-lib 0.27.0               [uses menhir]
=== install 1 package
  ∗ ollvm           0.99

ollvm is a very old package (11 years old) and if you look at the definition using opam show ollvm you can see that it requires menhir < 20211215, so opam has to downgrade menhir to be able to install this package.

Installing this version in a different temporary folder might work in this specific case as it is marked as a build dependency (although that doesn’t match the current spec for what build dependencies are), but it doesn’t help 99% of cases (very few dependencies are actually build dependencies) and adds a lot of complexities to opam that we can avoid.

Instead, if you want to avoid this downgrade, you can create a new (global or local) switch which wouldn’t have coq-lsp installed (unless you actually want to use both at the same time, in which case i’m not sure there is an easy way to do that)

1 Like