# Cannot upgrade OCAML to 5.2.0

**URL:** <https://discuss.ocaml.org/t/cannot-upgrade-ocaml-to-5-2-0/14888>\
**Category:** Learning\
**Tags:** build\
**Created:** [July 1, 2024, 6:59pm UTC](https://discuss.ocaml.org/t/cannot-upgrade-ocaml-to-5-2-0/14888 "2024-07-01T18:59:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhishes](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@abhishes](https://discuss.ocaml.org/u/abhishes)\
**Post date:** [July 1, 2024, 6:59pm UTC](https://discuss.ocaml.org/t/cannot-upgrade-ocaml-to-5-2-0/14888/1 "2024-07-01T18:59:35Z")

</div>

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.

```auto
% 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

```auto
<><> 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?

---

<div class="post-metadata">

**Author:** ![Chet\_Murthy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chet_murthy/32/1501_2.png) [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Post date:** [July 1, 2024, 7:04pm UTC](https://discuss.ocaml.org/t/cannot-upgrade-ocaml-to-5-2-0/14888/2 "2024-07-01T19:04:30Z")

</div>

~~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?

---

<div class="post-metadata">

**Author:** ![abhishes](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@abhishes](https://discuss.ocaml.org/u/abhishes)\
**Post date:** [July 1, 2024, 7:15pm UTC](https://discuss.ocaml.org/t/cannot-upgrade-ocaml-to-5-2-0/14888/3 "2024-07-01T19:15:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Chet\_Murthy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chet_murthy/32/1501_2.png) [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Post date:** [July 1, 2024, 7:31pm UTC](https://discuss.ocaml.org/t/cannot-upgrade-ocaml-to-5-2-0/14888/4 "2024-07-01T19:31:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kit-ty-kate](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/kit-ty-kate/32/5953_2.png) [@kit-ty-kate](https://discuss.ocaml.org/u/kit-ty-kate)\
**Post date:** [July 2, 2024, 10:17am UTC](https://discuss.ocaml.org/t/cannot-upgrade-ocaml-to-5-2-0/14888/5 "2024-07-02T10:17:24Z")

</div>

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

```auto
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](https://github.com/ocaml/opam-repository/issues/25961)

---

<div class="post-metadata">

**Author:** ![Zeta](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/zeta/32/6003_2.png) [@Zeta](https://discuss.ocaml.org/u/Zeta)\
**Post date:** [June 4, 2025, 2:35pm UTC](https://discuss.ocaml.org/t/cannot-upgrade-ocaml-to-5-2-0/14888/6 "2025-06-04T14:35:55Z")

</div>

I was having a different problem (opam update won’t actually update, preventing me to upgrade to 5.3.0), and this fixed the issue! What might have been the issue?

---

<div class="post-metadata">

**Author:** ![kit-ty-kate](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/kit-ty-kate/32/5953_2.png) [@kit-ty-kate](https://discuss.ocaml.org/u/kit-ty-kate)\
**Post date:** [June 4, 2025, 3:54pm UTC](https://discuss.ocaml.org/t/cannot-upgrade-ocaml-to-5-2-0/14888/7 "2025-06-04T15:54:57Z")

</div>

Without seeing the actual error message i can only speculate, but maybe something akin to [ocam/setup-ocaml#933](https://github.com/ocaml/setup-ocaml/pull/933)? If so, this should be fixed for good in opam 2.4 (currently available in alpha2), which moved to its own OCaml implementation of GNU patch.
