I can't install ocaml-lsp-server and ocaml-format-lib

I was able to reproduce in Docker and it’s a bug from Ubuntu 24.10.

# apt update && apt install opam
[...]
# ocaml
# #use "topfind";;
[...]
# #require "camlp-streams";;
/usr/lib/aarch64-linux-gnu/ocaml/5.2.0/camlp-streams: added to search path
/usr/lib/aarch64-linux-gnu/ocaml/5.2.0/camlp-streams/camlp_streams.cma: loaded
# Stream.empty;;
Error: Unbound module Stream
# ^D
# ls /usr/lib/aarch64-linux-gnu/ocaml/5.2.0/camlp-streams
META  camlp_streams.cma  camlp_streams.cmxs

Somehow installing opam, installs also a bunch of other unrelated things amongst which is libcamlp-streams-ocaml.
This package installs the cma and cmxs but also the META file for some reason and thus it is picked up by dune (although a local camlp-streams should have also been installed so i think there might be an issue in the priority given to OS-wide install vs. opam install).

So TL;DR: there are 3 bugs:

  • installing opam on ubuntu should not install libcamlp-streams-ocaml (to be reported in the Ubuntu or Debian bugtracker)
  • non -dev ocaml packages in Ubuntu should not have a META file (to be reported in the Ubuntu or Debian bugtracker)
  • Priority should be given to packages installed by opam instead of the ones installed system-wide (to be reported to the opam-repository bugtracker. EDIT: reported in ocaml/opam-repository#26824 and ocaml/dune#11062)

That said, to fix your current case:

opam switch set-invariant --switch=my_project ocaml-base-compiler.5.2.0
opam switch set-invariant --switch=default ocaml-base-compiler.5.2.0

this will ensure you’re using the ocaml toolchain as packages in opam-repository expect. In the future if you’re creating a new switch, use instead:

opam switch create <name> ocaml-base-compiler.<version>
3 Likes