Upgrade OCaml compiler in default opam switch

I’d like to upgrade the compiler version in my default opam switch to 4.12.0. I’m very new to OCaml, so I’m not even sure if this is a “normal” thing to do. The switch says it’s using compiler ocaml-system.4.10.0. I can see the latest version of this library is ocaml-system.4.12.0 on opam but when I opam update and opam upgrade ocaml-system it says there is nothing to do. When I run opam upgrade ocaml-system.4.12.0 I get an explicit error of:

[ERROR] ocaml-system = 4.12.0 unmet availability conditions: sys-ocaml-version = "4.12.0"

which seems to contradict what I see above on opam.

I have a feeling I’m going about this incorrectly, but I couldn’t find any explicit docs on upgrading the compiler, so any tips on how to correctly do this would be appreciated!

The system compiler is the one installed by a package manager (such as apt on debian) on your system. You can’t upgrade it using opam. In your case, I think that instead you should create a new switch with your desired ocaml version.

1 Like

Thank you, that’s nice to know. I’ve done what you suggest with opam switch create 4.12.0. Is there anything I should do to make that the “default” switch? Or can I just do an opam switch set 4.12.0 and then continue?

Yep and do eval (opam env) (fish shell) or bash eval `opam env` in bash.

2 Likes

default is a name like any other, it has no special meaning in opam (as far as I know). So there’s no particular reason to name a new switch default. I’d probably even advertise against doing it. But if you ever wanted to do it, it’s pretty simple

opam sw remove default # note that it won't remove the ocaml install on your system, just the opam switch
opam sw create default 4.12.0
1 Like