Opam error: Invalid_argument("OpamEnv.unzip_to")

Since the last few days, I get the following error message when trying to install opam packages:

[pkl@zeta ~]$ opam install merlin tuareg
The following actions will be performed:
  ∗ install merlin-lib        4.13-501 [required by merlin]
  ∗ install conf-emacs        1        [required by tuareg]
  ∗ install dot-merlin-reader 4.9      [required by merlin]
  ∗ install merlin            4.13-501
  ∗ install tuareg            3.0.1
===== ∗ 5 =====
Do you want to continue? [Y/n] y
Fatal error:
[pkl@zeta ~]$ opam --version

This happened to me but I was able to partially recover (my old switch still does not work) by recreating the opam env settings for my default switch:

OPAM_SWITCH_PREFIX='~/.opam/default'; export OPAM_SWITCH_PREFIX;
OCAML_TOPLEVEL_PATH='~/.opam/default/lib/toplevel'; export OCAML_TOPLEVEL_PATH;
CAML_LD_LIBRARY_PATH='~/.opam/default/lib/stublibs:/usr/local/lib/ocaml/4.08.1/stublibs:/usr/lib/ocaml/stublibs'; export CAML_LD_LIBRARY_PATH;

(your CAML_LD_LIBRARY_PATH will depend on where your default ocaml install is, version number etc.)

Once I was in my default switch I created a new switch. The new switch is 5.1.1 and the old was 5.1.0 but I do not know if this has anything to do why the new switch works and the old switch doesn’t.

Unfortunately, this did not solve the problem. The problem could be caused by the conf-openblas opam package. I have filed an issue here: Invalid_argument("OpamEnv.unzip_to") opam error after installing conf-openblas · Issue #25194 · ocaml/opam-repository · GitHub