Sane PATH variable in Emacs on Mac OS X

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”.


echo $PATH

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

  1. I have the following automatic configuration (from stackoverflow post):

    ;; from
    (defun set-exec-path-from-shell-PATH ()
    (let ((path-from-shell
    (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))))

  2. ;; 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:
    ;; ~/.MacOSX/environment.plist
    ;; 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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s