On Mac OS X the system PATH variable is not recognized by emacs. This means that one can not simply type
in the emacs shell to get into the database. The emacs shell complains about “binary not found”.
reveals that emacs just looks into /bin, /usr/bin, /sbin and /usr/sbin.
To set the $PATH variable inside emacs one can append the following lines to the .emacs file (found on github, hattip Alex Payne):
; sane path (setq path "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/mysql/bin") (setenv "PATH" path)
Next time Emacs starts one can go to the shell and
presents the database prompt.
4 thoughts on “Sane PATH variable in Emacs on Mac OS X”
I have the following automatic configuration (from stackoverflow post):
;; from http://stackoverflow.com/questions/2266905/emacs-is-ignoring-my-path-when-it-runs-a-compile-command
(defun set-exec-path-from-shell-PATH ()
(replace-regexp-in-string “[[:space:]\n]*$” “”
(shell-command-to-string “$SHELL -l -c ‘echo $PATH'”))))
(setenv “PATH” path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
;; On Mac OS X, GUI programs do not get a sensible PATH variable (i.e.
;; from /usr/libexec/path_helper). You can mitigate this by setting
;; the PATH variable in the binary plist file at this path:
;; Easiest way is using defaults:
;; defaults write $HOME/.MacOSX/environment PATH “$HOME/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin”
;; You will have to log out and back in for this to take effect.
Alternatively you can set your path in /etc/launchd.conf and it will be set globally for all applications including Terminal.app. man launchd.conf for more information.
You can use a little elisp library I wrote called exec-path-from-shell (https://github.com/purcell/exec-path-from-shell) to set your Emacs $PATH from that used in your shell. There are installable packages on Marmalade and Melpa (http://melpa.milkbox.net/).