I am running emacs 24.3 on mac os x 10.9. I have installed the tuareg-mode for ocaml programming but am unable to compile using the command C-c C-b. On pressing the same, the minibuffer asks me about 'Caml toplevel to run: ocaml'. When I press enter it shows the error "Searching for program: No such file or directory, ocaml". What am I missing?
Asked
Active
Viewed 1,519 times
2 Answers
1
you need to setup PATH
environment variable & the Emacs's exec-path
variable to correct values. One possibility is to use something like (in your ~/.emacs
):
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell (shell-command-to-string "$SHELL -c 'echo $PATH'")))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(when window-system (set-exec-path-from-shell-PATH))
to get the PATH
from shell and both variables correctly. One advantage of this is that you will setup PATH
only in one place - in your shell init script.

Alex Ott
- 80,552
- 8
- 87
- 132
-
So I understood the part about setting path variable in my emacs shell but wasn't the path already set in my shell init script when I installed ocaml. Why do I have to set it again. And pardon my ignorance. – user2239690 Dec 27 '13 at 14:28
-
When Emacs is started it's started from "initial" process, that doesn't have your PATH customizations - you can check this by executing the `M-x getenv PATH` and `C-h v exec-path` (before execution of my snippet of code) and comparing values with your actual shell output of `echo $PATH` ... – Alex Ott Dec 27 '13 at 15:30
-
That appears to have worked but now I have stumbled upon another problem. The error I get now is : "Fatal error: cannot open implicit module "Pervasives" Fatal error: exception Misc.Fatal_error". Apparently ocaml only runs under admin privileges in my bash shell. How can I achieve it from emacs! – user2239690 Dec 27 '13 at 17:28
-
I think, that it's something wrong with OCaml installation - how have you installed it? You can also look to following question: http://stackoverflow.com/questions/15712618/why-cant-pervasives-cmi-be-opened – Alex Ott Dec 27 '13 at 19:09
-
I downlaoded ocaml-4.01.dmg from the official website and installed it from there. – user2239690 Dec 27 '13 at 20:14
-
have you tried to set the `OCAMLLIB` environment variable as was pointed in the answer to question? – Alex Ott Dec 28 '13 at 09:48
1
So I found this cool mode that autoloads the shell variables into emacs environment for mac users. Very handy:
https://github.com/purcell/exec-path-from-shell
Just install it and update your .emacs file and you are set.

user2239690
- 81
- 1
- 10
-
Helped me, but when installing it from ELPA I had to add `(add-hook 'after-init-hook 'exec-path-from-shell-initialize)` to my init file instead of what the docs were saying. – Marcin Kaczmarek Oct 16 '14 at 18:28