6

I am attempting to install OCaml via the OCaml opam package manager on MacOs. I have successfully installed opam via homebrew. Initiating the package manager with opam init yields the following error:

[ERROR] Could not update repository "default":
        OpamDownload.Download_fail(_, "Curl failed: \"/usr/bin/curl
        --write-out %{http_code}\\\\n --retry 3 --retry-delay 2
        --user-agent opam/2.1.0 -L -o
        /private/var/folders/c_/6splkz692w16x82lzgnsxgfr0000gn/T/opam-57814-6b2069/index.tar.gz.part
        -- https://opam.ocaml.org/index.tar.gz\" exited with code 60")
[ERROR] Initial download of repository failed.

What can I do to facilitate successful connection to the repository and initialise opam?

Gerardo Zinno
  • 1,518
  • 1
  • 13
  • 35
  • Run `curl -v` for the URL that failed on the affected machine, and examine certificate-related error messages in the output. Your machine might not recognize the CA that issued the certificate, or one of the certificates in the chain (typically root CA, intermediate CA, server) has expired. If it’s the root CA cert, you need to provide your machine with an updated version of that root CA cert. – user149408 Feb 24 '23 at 16:51

4 Answers4

6

This error message indicates that curl is unable to establish the authenticity of the peer, i.e., https://opam.ocaml.org

This could happen because the certificates on either side are outdated. We can easily check if opam.ocaml.org is up-to-date, using one of the available online SSL checkers, e.g., this one says that they are OK. So it looks like that the problem is on your side.

First of all, you should try using your operating system upgrading options to get everything up-to-date.

If it is not an option, then you can use the --insecure option that you can pass using the OPAMFETCH environment variables. Or you can download the corresponding certificates and store a path to them in the ~/.curlrc, look here for more information.

ivg
  • 34,431
  • 2
  • 35
  • 63
  • Thank you for suggesting that the authentication issue is on my end. I've just upgraded my package manager in a failed attempt to remedy that issue. What other upgrading means should I attempt (short of opgrading macOS)? – Lucia Garcia Oct 11 '21 at 14:47
5

I had the same problem and solved it by first running brew install wget and then opam init, which suddenly worked.

Gerardo Zinno
  • 1,518
  • 1
  • 13
  • 35
3

I ran into the same issue and I found a workaround on the OCaml forum: here. (Credits to UnixJunkie)

You can run:

opam init github git+https://github.com/ocaml/opam-repository.git

This should avoid the certificate issues.

I tried to use ivg's solution but must have made a mistake in moving the .pem files, so I couldn't get that solution to work. The workaround was quick.

Update

The reason opam init failed for me was because curl was installed with snap on my system. Try to run opam init -verbose and that could reveal more about why you ran into an error. In my case I needed to install other things with opam and it kept failing every time. So snap uninstall curl and then sudo apt install curl fixed things. (Was only able to figure this out with help from my professor)

Tejas Anil Shah
  • 1,421
  • 11
  • 20
  • This let `opam init` succeed, but not (_e.g._) `opam repo add coq-released https://coq.inria.fr/opam/released`, so if you need other repos I would advise a different solution – D. Ben Knoble Oct 03 '22 at 15:58
1

Install curl first.

On MacOS: brew install curl

On Debian/Ubuntu Linux (and derivations): sudo apt-get install curl

glennsl
  • 28,186
  • 12
  • 57
  • 75