8
  1. How can I configure eshell to be able to run programs from directories in PATH env variable?

  2. How can I add additional custom directories to the list?

I use Emacs 24.3.1.

5 Answers 5

9

The Emacs equivalent of the PATH environment variable is exec-path, which is a list instead of a colon-separated string.

Its content it initialized with the value of PATH, so supposedly it should be all transparent. But if this happens not to contain what you want (typically when Emacs is not run from a shell, but from a Desktop Environment), you might find this package useful: exec-path-from-shell. Install it from Marmalade or MELPA using

M-x package-install exec-path-from-shell RET
4
  • 2
    If Emacs doesn't get your custom PATH when you start it from your desktop environment, it's because you didn't set your custom PATH in the right place. Set environment variables in .profile, not in .bashrc. Commented Sep 29, 2014 at 18:21
  • Copying export PATH=... to ~/.profiledid not work for me. I still see PATH set to value created by desktop environment. Commented Sep 29, 2014 at 20:45
  • 1
    @Gilles That's good advice generally, but doesn't help on OS X, where the user's shell is not involved in starting GUI apps such as Emacs.app.
    – sanityinc
    Commented Sep 30, 2014 at 13:03
  • @Gilles Adding things to $PATH does not make eshell see them, at least not on my system. Commented Feb 11, 2018 at 18:38
7

You can configure TRAMP to respect the PATH variable on the remote machine (for remote eshell sessions) by adding 'tramp-own-remote-path to the list 'tramp-remote-path:

(add-to-list 'tramp-remote-path 'tramp-own-remote-path)

By default, eshell will not adopt the remote PATH settings.

2
  • I don't see that this works. Perhaps, that's because I set and export a custom PATH in ~/.bash_profile (contrary to ~/.profile) which I have seen in some docs concerning these tramp-* vars... Commented Jan 26, 2015 at 20:03
  • I've asked specifically the question about eshell+tramp: emacs.stackexchange.com/q/7673/5165 If you have ideas why this might not work for me, I'd be grateful if you write about it there. Commented Jan 26, 2015 at 20:15
4

For a clear answer to part 2 (How can I add additional custom directories to the list?):

You can use the following elisp to customize your exec-path variable to include any additional directories

(add-to-list 'exec-path "/custom/directory/path")

Use case

Although the other answers specify how to add to your $PATH (%PATH% on Windows) there are cases where this is not really a solution, particularly in a Windows environment.

Suppose you have Cygwin installed and do not want to include c:\cygwin\bin in %PATH% (user or system) because it will overwrite certain DOS built-in commands (Find) and could break any scripts that call them.

Adding it directly to exec-path within Emacs on startup can ensure you get full access to those tools within the editor, without installing Cygwin Emacs.

1
  • Does not seem to work in Emacs 28.2 anymore. I have customized exec-path but the directories in which Eshell's which is searching does not change.
    – ceving
    Commented Nov 30, 2022 at 11:31
2

To answer to your first question: Eshell is already able to run programs in PATH. Here's an example:

Welcome to the Emacs shell

~ $ env-info

manuel@bebop

OS: LinuxBBQ Haggis
Uptime: 0d 4h 9m
Shell: /bin/zsh
WM: ratpoison
Disk: 37G / 257G
Mem: 1180M / 4042M
Kernel: Linux 3.16-2-686-pae i686
CPU: Intel(R) Core(TM)2 Duo CPU     T6400  @ 2.00GHz

~ $ which env-info
/home/manuel/bin/env-info
~ $ echo $PATH | grep bin
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/manuel/bin
1

For an even clearer answer to part 2 (How can I add additional custom directories to the list?): [this adds the current directory]

addpath (pwd)

or to add something relative to your current directory

addpath $(pwd)subdir1/subdir2

https://www.gnu.org/software/emacs/manual/html_mono/eshell.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.