Opam fails to install tuareg or caml-mode

Linux Mint
OCaml version 4.13.1
Opam version 2.1.2

Here’s the message I get when I try to install caml-mode:

> <><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
> ⬇ retrieved caml-mode.4.9  (https://opam.ocaml.org/cache)
> [ERROR] The compilation of conf-emacs.1 failed at "emacs --version".
> 
> #=== ERROR while compiling conf-emacs.1 =======================================#
> # context     2.1.2 | linux/x86_64 | ocaml.4.13.1 | https://opam.ocaml.org#dd31bfa8
> # path        ~/.opam/default/.opam-switch/build/conf-emacs.1
> # command     ~/.opam/opam-init/hooks/sandbox.sh build emacs --version
> # exit-code   1
> # env-file    ~/.opam/log/conf-emacs-13820-500d8c.env
> # output-file ~/.opam/log/conf-emacs-13820-500d8c.out
> ### output ###
> # bwrap: execvp emacs: No such file or directory
> 
> 
> 
> <><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
> ┌─ The following actions failed
> │ λ build conf-emacs 1
> └─ 
> ╶─ No changes have been performed

Here’s the message I get when I try to install tuareg:

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
⬇ retrieved tuareg.2.2.0  (cached)
⬇ retrieved user-setup.0.7  (cached)
[ERROR] The compilation of conf-emacs.1 failed at "emacs --version".

#=== ERROR while compiling conf-emacs.1 =======================================#
# context     2.1.2 | linux/x86_64 | ocaml.4.13.1 | https://opam.ocaml.org#dd31bfa8
# path        ~/.opam/default/.opam-switch/build/conf-emacs.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build emacs --version
# exit-code   1
# env-file    ~/.opam/log/conf-emacs-14361-c6dbf6.env
# output-file ~/.opam/log/conf-emacs-14361-c6dbf6.out
### output ###
# bwrap: execvp emacs: No such file or directory



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build conf-emacs 1
└─ 
╶─ No changes have been performed

Emacs was installed via the snap store. Emacs version is: GNU Emacs 27.2

You need emacs in your PATH and it seems it doesn’t exist.

Why would you install these via opam instead of MELPA?

2 Likes

Emacs is in my PATH.

@glennsl I Just assumed they had to be installed via opam… Someone within the great circle of OCaml knowledge should create a link where the rookies can go to see(in simple, straight forward steps) how Emacs, Vim, VS Code are set up for OCaml development.

2 Likes

If you’re using Emacs, I think you’re pretty much expected to have made the significant investment of comprehending the entire manual, and therefore be able to set it up by just reading the tuareg-mode README. Also, because Emacs is so configurable, it’s hard to give exact instructions that will work with everyone’s configuration. For example, I use Doom Emacs, where setting up OCaml is as simple as uncommenting a single line of configuration. But if it wasn’t, I’d have to translate the instructions to work with the Doom Emacs configuration framework. Which is fairly trivial, but still not something that can just be copied and pasted from a guide.

1 Like

Just fyi, there are detailed instructions on how to set up with VSCode, which is an area of focus for the editor support team: Up and Running with OCaml · OCaml Tutorials

The only official looking instructions I could find suggest using opam to install tuareg and merlin: Real World OCaml. Merlin in particular is opam switch specific, so that’s not so strange. That said, actually using emacs and merlin with more than one opam switch is a huge pain.

VS code setup is dead simple in comparison, so it’s good to see that’s where new users are being pointed.

1 Like

Tuareg’s readme says in its install section:

The easier way to install Tuareg is though the Emacs package system with NonGNU ELPA or MELPA (configuration).

Then follows with:

You can also install it using OPAM:

I think that’s pretty clear and as official as it gets, if you manage to find tuareg in the first place at least.

2 Likes

Just to add a second opinion, I usually install tuareg via opam rather than melpa, because it makes it easier to install all my editor plugins (i.e with merlin etc.) in one place - and it works out-of-the-box for me (debian), although I install emacs through apt.

Echoing @dbuenzli , the issue seems to be that when building conf-emacs, emacs isn’t in the PATH.

I think the issue might probably be related to the snap store not configuring your shell PATH correctly?

I’m not a hundred percent sure which files are loaded when setting up the env, but could it be that Emacs is added to your PATH in the initialisation scripts for your shell particular shell (i.e .zshrc if you’re using zsh), and not added to your path for whatever shell opam uses? Not sure if this is the cause of the problem, but it would be the first thing I would look into if I ran into this problem myself.

1 Like

I hate snap store, and flatpak, as they happen to have problems installing software properly, in my opinion. Usually better to use backport repository in Debian.

Anyways, I install support for emacs both ways, used to use Opam, but now use ELPA.
See my-init.org · master · Anders Jackson / Emacs Init · GitLab

1 Like