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.

whysoserious
  • 339
  • 3
  • 9

5 Answers5

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
Sigma
  • 4,510
  • 21
  • 27
  • 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`](http://unix.stackexchange.com/questions/3052/alternative-to-bashrc/3085#3085). – Gilles 'SO- stop being evil' Sep 29 '14 at 18:21
  • Copying `export PATH=...` to `~/.profile`did not work for me. I still see `PATH` set to value created by desktop environment. – whysoserious Sep 29 '14 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 Sep 30 '14 at 13:03
  • @Gilles Adding things to `$PATH` does not make eshell see them, at least not on my system. – Zelphir Kaltstahl Feb 11 '18 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.

  • 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... – imz -- Ivan Zakharyaschev Jan 26 '15 at 20:03
  • I've asked specifically the question about eshell+tramp: http://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. – imz -- Ivan Zakharyaschev Jan 26 '15 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.

Jonathan Leech-Pepin
  • 4,307
  • 1
  • 19
  • 32
  • 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 Nov 30 '22 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
Boccaperta-IT
  • 1,556
  • 11
  • 24
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

tjb
  • 197
  • 1
  • 7