TRAMP ignores tramp-remote-path
Asked Answered
C

2

11

I have the following in my .emacs:

(require 'tramp)
(add-to-list 'tramp-remote-path "/some/path")
(add-to-list 'tramp-remote-path 'tramp-default-remote-path)

so when I open a file using tramp over ssh, I expect my PATH to contain /some/path. Instead, running M-! echo $PATH returns

/bin:/usr/bin:/usr/sbin:/usr/local/bin

Even if I set export PATH=/hwdisks/data/modules/pkg/git/1.8.4.1/bin/git:$PATH in .bashrc or .profile, PATH is not set correctly.

In the tramp log, *debug tramp/ssh remotehost*, I can see tramp explicitly setting PATH:

12:28:34.202135 tramp-send-command (6) # PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin; export PATH

If I include echo "in .bashrc" in my .bashrc, it appears in the tramp log, so I know tramp is reading it.

How can I make tramp use the correct PATH?

Emacs version: 24.2.1
Tramp version: 2.2.3-24.1

Clichy answered 29/10, 2014 at 12:41 Comment(0)
C
16

Embarrassingly, the answer is in the tramp manual:

Another possibility is to reuse the path settings of your remote account when you log in. Usually, these settings are overwritten, because they might not be useful for tramp. The place holder tramp-own-remote-path preserves these settings. You can activate it via

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

I'm still not sure why it ignores the other paths added to tramp-remote-path.

Clichy answered 30/10, 2014 at 9:41 Comment(2)
Thank you for taking the time to come back here and post this answer after you found it. This is the only thing that I can do to tramp-remote-path that actually has any effect on the path.Myrta
I think that tramp-remote-path is used when TRAMP is trying to launch a "remote program" as described here as opposed to actually setting the $PATH variable. For this reason, I don't think you'll see your changes reflected in your remote shell, but if you e.g., try to use magit, it will look for git on the remote host based on what you've specified in tramp-remote-path.Conciliate
F
10

I read this in tramp manual and tried it. Added

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

Then exited emacs, removed ~/.emacs.d/tramp, and restarted as explained here

But M-! echo $PATH still shows the value of tramp-default-remote-path instead of the value set in my .bashrc.

The issue looks to be my understanding of how profiles are loaded. The way tramp calls the remote shell to get the remote PATH:

/bin/sh -l -c 'echo $PATH'
/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin

Since bash is call as login shell and as /bin/sh it reads .profile instead of .bash_profile or .bashrc.

I found this in bash manual page:

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order. The --noprofile option may be used to inhibit this behavior. When invoked as an interactive shell with the name sh, bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. Since a shell invoked as sh does not attempt to read and execute commands from any other startup files, the --rcfile option has no effect. A non-interactive shell invoked with the name sh does not attempt to read any other startup files. When invoked as sh, bash enters posix mode after the startup files are read.

I usually configure only ~/.bashrc and ~/.bash_profile For tramp to work properly looks like I should move my .bash_profile to .profile

Hope this helps others.

  • GNU Emacs: 25.0.94.2 Tramp: 2.2.13.25.1
Freud answered 17/6, 2016 at 16:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.