Setup on macosx for opam usage

dbuenzli edited this page Oct 21, 2014 · 4 revisions

Setting up environment variables for GUI programs on macosx has been a mess for quite some time now.

Compilation mode

If you are using compilation mode in it is likely that you won't have a correct environment (this can simply be checked by issuing env as the compilation command). There are various tips that will tell you how to adjust your $PATH, but it's not enough, there are other environment variables setup by opam.

A simple solution to this problem is to invoke the compilation mode shell as a login shell; this will read your .profile or .bash_profile file and everything should be setup correctly. This can be achieved by adding the following lines to your .emacs.

 ((eq window-system 'ns) ; macosx
  ;; Invoke login shells, so that .profile or .bash_profile is read
  (setq shell-command-switch "-lc")))

Interactive subshell

The subshell invoked through M-x shell tries to read from ~/.emacs_$SHELL or ~/.emacs.d/init_$ which is not very convenient maintenance wise. Like for compilation mode the easiest is to invoke the subshell as a login shell as this will read your .profile or .bash_profile. This can be achieved by settings the variable explicit-$SHELL-args in your .emacs. So for example if you are using bash just add:

(setq explicit-bash-args '("--login" "-i"))

to your .emacs file.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.