Re-installing ocaml

I decided to bite the bullet and completely re-install ocaml to take advantage of more features.
Installing opam 2.0.6 was difficult (bubblewrap) but it gave me an environment with
utop and accepting the following line:

~/ocaml/bubblewrap/build$ opam switch create 4.10.0

<><> Gathering sources ><><><><><><><>><><><><><><><><><><><>
[ocaml-base-compiler.4.10.0] downloaded from cache at https://opam.ocaml.org/cache

<><> Processing actions <><><><>><><><><><><><><><><><><><><><><><><>
∗ installed base-bigarray.base
∗ installed base-threads.base
∗ installed base-unix.base
∗ installed ocaml-base-compiler.4.10.0
∗ installed ocaml-config.1
∗ installed ocaml.4.10.0
Done.
So far so good. Then as requested :

~/ocaml/bubblewrap/build$ eval (opam env) ~/ocaml/bubblewrap/build ocamlo
ocamlobjinfo ocamlobjinfo.opt ocamlopt.byte ocamloptp
ocamlobjinfo.byte ocamlopt ocamlopt.opt
~/ocaml/bubblewrap/build$

at this stage ocamlopt was there
ocamlopt --version
4.10.0

Now I should be ready to install dune in preparation for all the others packages.
Alas, dune does not install, because opam thinks bubblewrap is not installed???
opam

~/ocaml/bubblewrap$ sudo opam install dune

[sudo] password for peter:
The following actions will be performed:
∗ install dune 2.4.0

<><> Gathering sources ><><>><><><><><><><><><><><><><><><><><><><>
[dune.2.4.0] found in cache

<><> Processing actions <><><><><><><><><><><><><><><><><><>
[ERROR] The compilation of dune failed at “/home/peter/.opam/opam-init/hooks/sandbox.sh
build ocaml bootstrap.ml -j 7”.

#=== ERROR while compiling dune.2.4.0 =========================================#
context 2.0.6 | linux/x86_64 | ocaml-base-compiler.4.10.0 | https://opam.ocaml.org#62108b6c
path ~/.opam/4.10.0/.opam-switch/build/dune.2.4.0
command ~/.opam/opam-init/hooks/sandbox.sh build ocaml bootstrap.ml -j 7
exit-code 10
env-file ~/.opam/log/dune-31354-e7966f.env
output-file ~/.opam/log/dune-31354-e7966f.out
The ‘bwrap’ command was not found. Install ‘bubblewrap’ on your system, or
disable sandboxing in ~/.opam/config at your own risk.

Are there any up-to-date instructions?

Looks like you are on some kind of linux distro so: https://command-not-found.com/bwrap

Can you point to which instructions you were following? There’s no mention of ‘bubblewrap’ in the opam installation instructions page: http://opam.ocaml.org/doc/Install.html

At the end of the error above you get:

...
The ‘bwrap’ command was not found. Install ‘bubblewrap’ on your system, or
disable sandboxing in ~/.opam/config at your own risk.

It is maybe not the best experience :slight_smile: but at least we have something :slight_smile:

opam.ocaml.org/doc/Install.html is, in fact, where I started.
As a result I got
∗ installed base-bigarray.base
∗ installed base-threads.base
∗ installed base-unix.base
∗ installed ocaml-base-compiler.4.10.0
∗ installed ocaml-config.1
∗ installed ocaml.4.10.0
Done.
But at that time only the top level is installed. Just to test the installation I tried “opam install containers”.
It turns out, containers uses dune internally, to install, and that is where I got complaints about bubble wrap. (containers wants to install a whole lot of things of which only the first, ‘seq’ succeeded.)
I found a way to install bubblewrap.
https://github.com/ocaml/opam/issues/3424

But then the install aborted with a claim it could not find “m4”. Since this absurd I am beginning to believe the path is not set correctly after “eval $(opam env)”.

At any rate I will try to redo everything going back to opam 1.2.

It looks like you’re past building opam, but just in case, when I wanted to get ocaml running on a Debian machine, where opam was very backlevel, I installed the opam binary distribution, used that to get an ocaml switch, and from there was able to build everything I needed, including opam itself (just to be sure it worked – I didn’t use it).

Can you mention the following:

  • What is your operating system/distro
  • What are the steps you used to install OCaml/opam/etc. (what were the exact commands you ran)

Thanks.

Thank you; this turns out to be very helpful.
I am on Ubuntu 16.04 LTS (4 year support)
So after apt-get install opam I have a working opam 2.0.6
It turns out we can live with this this BUT:
AT THIS STAGE THE FOLLOWING LINES MUST BE REMOVED FROM ~/.opam/config

wrap-build-commands:
["%{hooks}%/sandbox.sh" “build”] {os = “linux” | os = “macos”}
wrap-install-commands:
["%{hooks}%/sandbox.sh" “install”] {os = “linux” | os = “macos”}
wrap-remove-commands:
["%{hooks}%/sandbox.sh" “remove”] {os = “linux” | os = “macos”}

Otherwise it wants bwrap. In my case even when it is installed, opam does not
find it…
Now we are in business.
~/ocaml/xy$ sudo opam install lwt uutf uucp str bigarray re sexplib higher

I suspect opam 2.0… is not yet used a lot. (containers still does not compile but this
is not an opam problem)
BTW: opam 2 compiles a lot faster, as it uses multiple cores quite effectively

Ah yes, I remember having to do that when I got opam working some machine … I forget when it was, so long ago I forgot. Though, isn’t bubblewrap how (newer versions of) opam is able to figure out what to remove when you uninstall a package, without needing a package-uninstall command?

Maybe it’s necessary these days? I’m not saying it is, and I haven’t checked b/c I use a more-recent Ubuntu, but … maybe somebody reading this knows the answer? That is, "what exactly is lost by disabling “bwrap” ?

Bubblewrap is used on Linux to run installation commands in a sandbox. Opam uses sandbox-exec on macOS. You can disable it while setting up opam using the —disable-sandbox flag. Bubblewrap is preinstalled on most recent Linux distros, and while opam will work without it, it’s probably nice to enable support for it as the default option.

More details at https://opam.ocaml.org/doc/FAQ.html#Why-does-opam-require-bwrap

1 Like

Thank you! Yeah, that’s what I remember (from back when I dug into this while debugging my install problem). Thank you!

Doesn’t Ubuntu 16.04 LTS have a bubblewrap package available, even if via a PPA? Maybe you need a later version of Ubuntu. At any rate, I have a bubblewrap package installed for my particular distribution, installed in the /usr prefix in the ordinary way, and opam finds it correctly.