Issue
I need to use my $PATH
in Emacs to run some commands. How can I make Emacs use it? I installed Emacs from Ubuntu repositories.
Solution
Here's a trick I use to ensure my GUI Emacs always sees the same $PATH
that I get inside a shell:
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell (replace-regexp-in-string
"[ \t\n]*$"
""
(shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq eshell-path-env path-from-shell) ; for eshell users
(setq exec-path (split-string path-from-shell path-separator))))
(when window-system (set-exec-path-from-shell-PATH))
Specifically, on OS X, a graphical Emacs will not pick up the user's shell's definition of $PATH
, so this trick helps me on that platform.
Update: this code has now been published as an elisp library called exec-path-from-shell and installable packages are available in MELPA.
Answered By - sanityinc Answer Checked By - Marilyn (WPSolving Volunteer)