I just installed OCaml on my computer (macOS Monterrey, M1, which seems to be the cause of lots of issues). Following this guide, I ran:
brew install opam
opam init
eval `opam env`
opam switch create 4.13.1
eval `opam env`
Then created a new directory, went into it and
dune init exe helloworld
dune build
And got
Error: Program ocamlc not found in the tree or in PATH
Lots of things seem to be broken.
What did I do wrong?
Itās eval "$(opam env)" (same as eval "`opam env`").
opam env alone prints a bunch of shell commands, which extend your PATH variable so that programs like ocamlc could be located. You need to run these commands, which is achieved with eval.
Edit: oh I see thatās what you probably did but didnāt enclose the commands within multiple ticks. You would type ``eval `opam env` `` to render eval `opam env` .
there isnāt any issues for me on Monterrey/M1.
Trying to guess whatās wrong here, did you change terminal between the last
eval `opam env`
and the āError: Program ocamlc not foundā ?
If yes, what might have happened is that opam init asked you if you wanted to modify your ~/.zshrc file but the default is ānoā. See message as to why it is important:
<><> Required setup - please read <><><><><><><><><><><><><><><><><><><><><> š«
In normal operation, opam only alters files within ~/.opam.
However, to best integrate with your system, some environment variables
should be set. If you allow it to, this initialisation step will update
your zsh configuration by adding the following line to ~/.zshrc:
[[ ! -r /Users/kit_ty_kate/.opam/opam-init/init.zsh ]] || source /Users/kit_ty_kate/.opam/opam-init/init.zsh > /dev/null 2> /dev/null
Otherwise, every time you want to access your opam installation, you will
need to run:
eval $(opam env)
You can always re-run this setup with 'opam init' later.
Do you want opam to modify ~/.zshrc? [N/y/f]
(default is 'no', use 'f' to choose a different file)
I donāt personally know why it is ānoā by default but maybe it can be improved.
the backticks are there in the original post, just not really well shown by Discourse.
Thanks for responding to my vague and hard to reproduce issue⦠And good call about not modifying the .zshrc. I had skipped that step, but then regretted it afterwards and added that line to my .zshrc manually.
In any case: I did rm -rf ~/.opam && brew remove opam, started a new shell and reran everything from the beginning, and itās all working now.