How to install specific OCaml version with OPAM 2.0 beta 3?

opam

#1

I’ve installed opam 2.0, but can’t seem to figure out how to install a specific version of OCaml. I see that they’re supposed to be their own packages now, but I haven’t been able to figure out the right incantation.

I’m now at the point where opam sees my system ocaml, and fails because of a version mismatch.

$ opam install ocaml
The following actions will be performed:
  - install ocaml 4.04.1

=-=- Gathering sources =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[ERROR] The compilation of ocaml failed at "ocaml unix.cma gen_ocaml_config.ml".

#=== ERROR while compiling ocaml.4.04.1 =======================================#
# command      ocaml unix.cma gen_ocaml_config.ml
# path         /src/_opam/.opam-switch/build/ocaml.4.04.1
# exit-code    1
# env-file     /home/opam/.opam/log/ocaml-34-05296d.env
# output-file  /home/opam/.opam/log/ocaml-34-05296d.out
### output ###
# OCaml version mismatch: 4.01.0, expected 4.04.1



=-=- Error report -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+- The following actions failed
| - build ocaml 4.04.1
+-
- No changes have been performed

#2

I install switches the same way as before with:

$  opam switch create 4.04.2 ocaml-base-compiler.4.04.2

The only thing to note is that all the switch names have been renamed.

You can list your 4.05 switches with

$ opam switch list-available 4.05.0

for example.


#3

Thank you as always, Rudi!

I install switches the same way as before

That seems quite different from opam switch install -A 4.04.1 my-switch :slight_smile:

I didn’t find this documentation on any of the release notes. Is it opam switch create <switch-name> <ocaml-package>? And is there a public listing outside of opam of all of the valid inputs for ocaml-package (though opam switch list-available 4.05.0 seems nice too)?


#4

Admittedly, I haven’t read the release notes so can’t help you there. But the documentation in opam itself is all correct: $ opam switch --help.


#5

The confusing part, here, — apologies for it — is that the ocaml package is actually a virtual one, that serves as a transition layer between the usual packages (that should just state depends: "ocaml"), and the various implementation ocaml-base-compiler, ocaml-system, ocaml-variants. It will refuse to install, as it did above, if the actual implementation found doesn’t match its version.

It’s indeed opam switch create <switch-name> <ocaml-package>, but with some magic allowed (when the name and package are the same, and if you specify a non-ambiguous version instead of a package name, it will still work). The alternative is opam switch create <name> --empty, which doesn’t set any base packages and lets you free to deal with the compiler as with other packages. (side note: using --empty may lead to poor to terrible performance with aspcud, on the current release, but is much better with the new built-in solver on recent master)


#6

The online opam introduction doesn’t mention the create syntax, nor install, fwiw.