Sane PATH variable in Emacs on Mac OS X

16 08 2011

On Mac OS X the system PATH variable is not recognized by emacs. This means that one can not simply type

mysql

in the emacs shell to get into the database. The emacs shell complains about “binary not found”.

Indeed

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

mysql

presents the database prompt.

About these ads

Actions

Information

4 responses

16 08 2011
Juan Pechiar

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 ()
(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))))

16 08 2011
rdj

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

22 08 2011
Zane Shelby (@zaneshelby)

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.

13 09 2012
Steve

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/).

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Connecting to %s




Follow

Get every new post delivered to your Inbox.

%d bloggers like this: