Why does opam need to set the environment?

The whole mechanic around needing to keep your environment in sync is pretty clunky - it requires hooks in your shell to make convenient, and does not work well with local switches. Why isn’t all the information just stored in a config file that opam looks at – for global switches, in the the user’s home directory or some similarly “global” location, and for local switches, in the directory of the switch?

2 Likes

It is not required; it is just a convenience to bring the binaries installed into the switch into your PATH and the like. But it is always possible to simply prefix all your OPAM-using commands with opam exec and leave your environment alone (this is what I do).

Cheers,
Nicolas

5 Likes

The OCaml compiler or interpreter doesn’t know about the opam settings, then it needs to know where to get libraries. This explains why OPAM set the CAML_LD_LIBRARY_PATH environment variable depending of the selected switch. Your shell doesn’t know which compiler to use when multiple Ocaml versions are installed. This explains why OPAM also set the PATH variable.

1 Like