Trouble with `opam init`

Hi everyone!

I followed the installation guide at Install OCaml – OCaml, using brew on Mac M1. At the step where I’m supposed to run opam init, I got:

$ opam init -v
No configuration file found, using built-in defaults.
Checking for available remotes: rsync and local, git.
  - you won't be able to use mercurial repositories unless you install the hg command on your system.
  - you won't be able to use darcs repositories unless you install the darcs command on your system.


<><> Fetching repository information ><><><><><><><><><><><><><><><><><><><>  🐫
[default] Initialised
[ERROR] Could not update repository "default": /opt/homebrew/bin/opam: "create_process" failed on /opt/homebrew/opt/openssl: Permission denied
[ERROR] Initial download of repository failed.
'opam init -v' failed.

When I Googled for the error message (“opam init” create_process openssl), all issues I’ve found seem to be about Cygwin on Windows not being able to find sh, which is not the case for my situation. So I’m kinda stuck. What should I do?

Here’s the result of opam init -v -v, in case it’s useful:

$ opam init -v -v
No configuration file found, using built-in defaults.
Checking for available remotes: rsync and local, git.
  - you won't be able to use mercurial repositories unless you install the hg command on your system.
  - you won't be able to use darcs repositories unless you install the darcs command on your system.

+ /Users/sorawee/.opam/opam-init/hooks/sandbox.sh "build" "sh" "-c" "echo SUCCESS >$TMPDIR/opam-sandbox-check-out && cat $TMPDIR/opam-sandbox-check-out; rm -f $TMPDIR/opam-sandbox-check-out"
- SUCCESS

<><> Fetching repository information ><><><><><><><><><><><><><><><><><><><>  🐫
+ /opt/homebrew/bin/wget "--content-disposition" "-t" "3" "-O" "/private/var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-15331-7b8acb/index.tar.gz.part" "-U" "opam/2.1.2" "--" "https://opam.ocaml.org/index.tar.gz"
- --2022-04-02 20:37:12--  https://opam.ocaml.org/index.tar.gz
- Resolving opam.ocaml.org (opam.ocaml.org)... 54.146.41.74
- Connecting to opam.ocaml.org (opam.ocaml.org)|54.146.41.74|:443... connected.
- HTTP request sent, awaiting response... 200 OK
- Length: 5217105 (5.0M) [application/gzip]
- Saving to: ‘/private/var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-15331-7b8acb/index.tar.gz.part’
-
-      0K .......... .......... .......... .......... ..........  0%  153K 33s
<elided>
-   5050K .......... .......... .......... .......... ....      100% 79.7M=1.9s
-
- 2022-04-02 20:37:14 (2.61 MB/s) - ‘/private/var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-15331-7b8acb/index.tar.gz.part’ saved [5217105/5217105]
-
+ /usr/bin/tar "xfz" "/private/var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-15331-7b8acb/index.tar.gz" "-C" "/Users/sorawee/.opam/repo/default.new"
[default] Initialised
+ /usr/bin/tar "cfz" "/Users/sorawee/.opam/repo/default.tar.gz.tmp" "-C" "/Users/sorawee/.opam/repo" "default"
[ERROR] Could not update repository "default": /opt/homebrew/bin/opam: "create_process" failed on /opt/homebrew/opt/openssl: Permission denied
[ERROR] Initial download of repository failed.
'opam init -v -v' failed.
1 Like

Doesn’t look like an opam problem, but rather a problem with your openssl executable. Are you able to execute /opt/homebrew/opt/openssl? If you get the same error (Permission denied), you can try reinstalling it with Homebrew to see if that solves your problem.

Cheers,
Nicolas

Well, that path is a directory on my system! The executable is at /opt/homebrew/opt/openssl/bin/openssl, and it works fine:

$ /opt/homebrew/opt/openssl/bin/openssl version
OpenSSL 1.1.1n  15 Mar 2022

I suspect the error message to lie. Can tar unpack to the desired location or does it fail? Also create_process sounds a bit odd.

Can the opam specialists have a look?

Could you try to run opam init -vvv --debug-level=3 for more debug output?

Sure. It doesn’t look like there’s any useful information, but here’s the result:

00:00.048  CLI                    Parsing CLI version 2.1
No configuration file found, using built-in defaults.
00:00.052  CLIENT                 INIT
Checking for available remotes: rsync and local, git.
  - you won't be able to use mercurial repositories unless you install the hg command on your system.
  - you won't be able to use darcs repositories unless you install the darcs command on your system.

00:00.064  SYSTEM                 mkdir /Users/sorawee/.opam
00:00.064  SYSTEM                 mkdir /Users/sorawee/.opam/opam-init
00:00.064  SYSTEM                 mkdir /Users/sorawee/.opam/opam-init/hooks
00:00.064  SYSTEM                 mkdir /var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-73482-a44e0e
00:00.065  SYSTEM                 mkdir /var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-sorawee-73482
+ /Users/sorawee/.opam/opam-init/hooks/sandbox.sh "build" "sh" "-c" "echo SUCCESS >$TMPDIR/opam-sandbox-check-out && cat $TMPDIR/opam-sandbox-check-out; rm -f $TMPDIR/opam-sandbox-check-out"
- SUCCESS
00:00.228  SYSTEM                 [log-73482-d4d089] (in 0.163s) /Users/sorawee/.opam/opam-init/hooks/sandbox.sh build sh -c echo SUCCESS >$TMPDIR/opam-sandbox-check-out && cat $TMPDIR/opam-sandbox-check-out; rm -f $TMPDIR/opam-sandbox-check-out
00:00.228  SYSTEM                 rmdir /var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-73482-a44e0e
00:00.232  FILE(config)           Wrote /Users/sorawee/.opam/config in 0.000s
00:00.232  SYSTEM                 mkdir /Users/sorawee/.opam/repo
00:00.232  FILE(repos-config)     Wrote /Users/sorawee/.opam/repo/repos-config in 0.000s
00:00.232  CLIENT                 updating repository state
00:00.232  GSTATE                 LOAD-GLOBAL-STATE @ /Users/sorawee/.opam
00:00.232  SYSTEM                 LOCK /Users/sorawee/.opam/lock (none => read)
00:00.232  SYSTEM                 LOCK /Users/sorawee/.opam/config.lock (none => write)
00:00.233  FILE(config)           Read ~/.opam/config in 0.000s
00:00.233  RSTATE                 LOAD-REPOSITORY-STATE @ /Users/sorawee/.opam
00:00.233  SYSTEM                 LOCK /Users/sorawee/.opam/repo/lock (none => write)
00:00.233  FILE(repos-config)     Read ~/.opam/repo/repos-config in 0.000s
00:00.233  RSTATE                 No cache found
00:00.233  FILE(repo)             Cannot find /Users/sorawee/.opam/repo/default/repo
00:00.233  RSTATE                 loaded opam files from repo default in 0.000s
00:00.233  SYSTEM                 LOCK /Users/sorawee/.opam/repo/state-11ABC690.cache (none => write)
00:00.233  CACHE(repository)      Writing the repository cache to ~/.opam/repo/state-11ABC690.cache ...
00:00.233  CACHE(repository)      ~/.opam/repo/state-11ABC690.cache written in 0.000s
00:00.233  SYSTEM                 LOCK /Users/sorawee/.opam/repo/state-11ABC690.cache (write => none)

<><> Fetching repository information ><><><><><><><><><><><><><><><><><><><>  🐫
00:00.233  PARALLEL               Iterate over 1 task(s) with 3 process(es)
00:00.233  PARALLEL               Starting job 0 (worker 1/3): 0
00:00.233  REPOSITORY             update default from https://opam.ocaml.org
00:00.233  CURL                   pull-repo-update
00:00.233  SYSTEM                 mkdir /Users/sorawee/.opam/repo/default.new
00:00.233  SYSTEM                 mkdir /var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-73482-fd6c07
00:00.233  PARALLEL               Next task in job 0: /opt/homebrew/bin/wget --content-disposition -t 3 -O /private/var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-73482-fd6c07/index.tar.gz.part -U opam/2.1.2 -- https://opam.ocaml.org/index.tar.gz
Processing  1/1: [default: http]
+ /opt/homebrew/bin/wget "--content-disposition" "-t" "3" "-O" "/private/var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-73482-fd6c07/index.tar.gz.part" "-U" "opam/2.1.2" "--" "https://opam.ocaml.org/index.tar.gz"
- --2022-04-04 10:30:46--  https://opam.ocaml.org/index.tar.gz
- Resolving opam.ocaml.org (opam.ocaml.org)... 54.146.41.74
- Connecting to opam.ocaml.org (opam.ocaml.org)|54.146.41.74|:443... connected.
- HTTP request sent, awaiting response...
- 200 OK
- Length: 5220856 (5.0M) [application/gzip]
- Saving to: ‘/private/var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-73482-fd6c07/index.tar.gz.part’
-
-      0K .......... .......... .......... .......... ..........  0%  300K 17s
<elided>
-   5050K .......... .......... .......... .......... ........  100% 15.1M=0.8s
-
- 2022-04-04 10:30:47 (6.07 MB/s) - ‘/private/var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-73482-fd6c07/index.tar.gz.part’ saved [5220856/5220856]
-
00:02.094  PARALLEL               Collected task for job 0 (ret:0)
+ /bin/mv "/private/var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-73482-fd6c07/index.tar.gz.part" "/private/var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-73482-fd6c07/index.tar.gz"
00:02.099  SYSTEM                 [log-73482-b8fd6a] (in 0.005s) mv /private/var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-73482-fd6c07/index.tar.gz.part /private/var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-73482-fd6c07/index.tar.gz
00:02.099  PARALLEL               Next task in job 0: /usr/bin/tar xfz /private/var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-73482-fd6c07/index.tar.gz -C /Users/sorawee/.opam/repo/default.new
+ /usr/bin/tar "xfz" "/private/var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-73482-fd6c07/index.tar.gz" "-C" "/Users/sorawee/.opam/repo/default.new"
00:05.950  PARALLEL               Collected task for job 0 (ret:0)
00:05.950  SYSTEM                 rmdir /var/folders/8v/ssfgpb5d67n4jrvmszsh7y800000gn/T/opam-73482-fd6c07
00:05.954  REPOSITORY             default: applying update from scratch at /Users/sorawee/.opam/repo/default.new
00:05.954  SYSTEM                 rmdir /Users/sorawee/.opam/repo/default
+ /bin/mv "/Users/sorawee/.opam/repo/default.new" "/Users/sorawee/.opam/repo/default"
00:05.958  SYSTEM                 [log-73482-2b546c] (in 0.004s) mv /Users/sorawee/.opam/repo/default.new /Users/sorawee/.opam/repo/default
[default] Initialised
00:05.958  FILE(repo)             Read ~/.opam/repo/default/repo in 0.000s
00:05.958  FILE(repo)             Read ~/.opam/repo/default/repo in 0.000s
00:05.958  PARALLEL               Next task in job 0: /usr/bin/tar cfz /Users/sorawee/.opam/repo/default.tar.gz.tmp -C /Users/sorawee/.opam/repo default
Processing  1/1:
+ /usr/bin/tar "cfz" "/Users/sorawee/.opam/repo/default.tar.gz.tmp" "-C" "/Users/sorawee/.opam/repo" "default"
00:08.620  PARALLEL               Collected task for job 0 (ret:0)
+ /bin/mv "/Users/sorawee/.opam/repo/default.tar.gz.tmp" "/Users/sorawee/.opam/repo/default.tar.gz"
00:08.622  SYSTEM                 [log-73482-b6ba93] (in 0.002s) mv /Users/sorawee/.opam/repo/default.tar.gz.tmp /Users/sorawee/.opam/repo/default.tar.gz
00:08.625  FILE(opam)             Read ~/.opam/repo/default/packages/touist/touist.3.2.1/opam in 0.000s
<elided>
00:08.689  FILE(opam)             Read ~/.opam/repo/default/packages/protocol-9p/protocol-9p.0.10.0/opam in 0.000s
00:08.689  FILE(opam)             Read ~/.opam/repo/default/packages/protocol-9p/protocol-9p.2.0.2/opam in 0.000s
00:08.689  FILE(opam)             Read ~/.opam/repo/default/packages/protocol-9p/protocol-9p.0.8.0/opam in 0.000s
00:08.689  FILE(opam)             Read ~/.opam/repo/default/packages/tezos-clic/tezos-clic.9.2/opam in 0.000s
00:08.690  FILE(opam)             Read ~/.opam/repo/default/packages/tezos-clic/tezos-clic.10.2/opam in 0.000s
00:08.690  FILE(opam)             Read ~/.opam/repo/default/packages/tezos-clic/tezos-clic.7.4/opam in 0.000s
[ERROR] Could not update repository "default": /opt/homebrew/bin/opam: "create_process" failed on /opt/homebrew/opt/openssl: Permission denied
00:08.691  PARALLEL               Job 0 finished
00:08.691  FILE(repos-config)     Wrote /Users/sorawee/.opam/repo/repos-config in 0.000s
00:08.691  SYSTEM                 rm /Users/sorawee/.opam/repo/state-11ABC690.cache
00:08.691  SYSTEM                 LOCK /Users/sorawee/.opam/repo/state-11ABC690.cache (none => write)
00:08.691  CACHE(repository)      Writing the repository cache to ~/.opam/repo/state-11ABC690.cache ...
00:08.691  CACHE(repository)      ~/.opam/repo/state-11ABC690.cache written in 0.000s
00:08.691  SYSTEM                 LOCK /Users/sorawee/.opam/repo/state-11ABC690.cache (write => none)
00:08.691  SYSTEM                 rmdir /Users/sorawee/.opam
[ERROR] Initial download of repository failed.
'opam init -vvv --debug-level=3' failed.

what do env and ls -l /opt/homebrew/opt return?

Here are relevant entries:

$ env
...
PATH=/Users/sorawee/.elan/bin:/Users/sorawee/projects/solvers:/Applications/CoqIDE_8.13.0.app/Contents/Resources/bin:/Users/sorawee/projects/racket/racket/bin/:/opt/homebrew/bin:/opt/homebrew/opt:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Users/sorawee/projects/racket/racket/bin:/Library/TeX/texbin:/Users/sorawee/.local/bin
...
$ ls -l /opt/homebrew/opt/openssl
lrwxr-xr-x  1 sorawee  wheel  28 Apr  2 20:11 /opt/homebrew/opt/openssl@ -> ../Cellar/openssl@1.1/1.1.1n

What happened here is that opam try to find openssl in PATH, find the directory /opt/homebrew/opt/openssl, but it’s not the binary.
It’s more an system install / path specification issue: PATH paths are supposed to contain executables at toplevel, and you have a (or more?) directory in /opt/homebrew/opt/.

I was running into the same error when trying to install ssl. My problem was that I had added this line to my .zprofile file:

export PATH=/opt/homebrew/Cellar:$PATH

Dropping that line solved the issue for me. I hope future readers find this useful!