Cannot upgrade OCAML to 5.2.0

Hello when I do a opam update on my computer I see this

[WARNING] Invalid patch utility. Please install GNU patch
Now run ‘opam upgrade’ to apply any package updates.

% opam upgrade
The following actions will be performed:
  ∗ install ocaml        5.2.0
  ∗ install base-domains base
  ∗ install base-nnp     base
===== ∗ 3 =====
Do you want to continue? [Y/n] Y

But when I run opam upgrade

I see

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
[ERROR] The compilation of ocaml.5.2.0 failed at "ocaml /Users/abhisheksrivastava/.opam/default/share/ocaml-config/gen_ocaml_config.ml
        5.2.0 ocaml".

#=== ERROR while compiling ocaml.5.2.0 ========================================#
# context     2.1.6 | macos/arm64 |  | https://opam.ocaml.org#01e40b8e
# path        ~/.opam/default/.opam-switch/build/ocaml.5.2.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build ocaml /Users/abhisheksrivastava/.opam/default/share/ocaml-config/gen_ocaml_config.ml 5.2.0 ocaml
# exit-code   2
# env-file    ~/.opam/log/ocaml-14631-be84a2.env
# output-file ~/.opam/log/ocaml-14631-be84a2.out
### output ###
# Cannot find file /Users/abhisheksrivastava/.opam/default/share/ocaml-config/gen_ocaml_config.ml.

What can I do to fix the issue?

I have no idea what sort of machine you’re on: can you provide that information? OS, machine architecture, possibly the output of lsb_release -a, etc?

o.i.c. macos.

the warning message suggests that the program patch is not what is expected. Have you looked into that? patch is a pretty fundamental program for development.

ETA: Have you previously been able to install OCaml versions using opam on this machine?

Yes I had a working installation some time back. Not sure what did I do to break it.

Can I like clear everything and do a fresh install? how can I do that?

OK

  1. first thing I would do in your situation, is to nuke one of the switches you’d previously created, and recreate it. Ideally, you would do that with the most up-to-date switch you’d successfully created (e.g. 5.1.0 maybe?) If that works, then perhaps there’s something weird going on with the new release.
  2. If you cannot recreate that switch you’d previously created, then yeah, I’d nuke the entire OPAM installation and recreate it.
  3. Instead of “nuking” the OPAM installation, you could just rename it to another directory (e.g. if you have it in ~/.opam then maybe move that to ~/dot.opam.MOVED (so you’ll remember it) and then recreate as if you’re installing OPAM from-scratch

ALTERNATIVE: set your OPAMROOT environment variable to some alternative directory – that will allow you to do the step #2 without having to move your ~/.opam directory.

If you cannot recreate your OPAM environment from-scratch, then yeah, you’ve probably messed-up your Mac env somehow.

The way to fix this is to run the following commands:

brew install gpatch
rm -rf ~/.opam/repo/default{,.tar.gz} && opam update default

The issue is described in: Possible breakage in opam update · Issue #25961 · ocaml/opam-repository · GitHub

4 Likes