Your diagnosis is probably correct.
To circumvent the problem, you need to verify which rcfile is not executed at startup (it will likely be the one where PATH is set up), among the scripts in the answer you refer to.
Then, you could rewrite your ~/.bashrc
to avoid the problem.
Or you could try and change the command:
ssh <user>@<ip> '. /etc/profile; pyenv versions'.
This will import /etc/profile
into the current executing shell. You might need to import /etc/bashrc
or ~/.profile
instead of /etc/profile
, or dot them both (note there is a space between the dot and the file name; also, the whole command is quoted).
Testing (on Ubuntu)
Logging in on a handy virtual machine:
leonardo@aladdin:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/opt/android-sdk-linux/platform-tools:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
leonardo@aladdin:~$ logout
Now trying with straight SSH:
$ ssh leonardo@aladdin "echo \$PATH"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Okay. So, different PATHs. Where does, say, that java-8-oracle come from? You will do some similar check, with some lengthy string in the PATH that is only there when in a login shell.
As root from the VM, I look for that string following a PATH assignation, everywhere in /etc
(should it not work, I'll retry with the home dotfiles by specifying /home/.*
).
# grep -r PATH.*java-8-oracle /etc
/etc/profile.d/jdk.csh:setenv PATH ${PATH}:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
/etc/profile.d/jdk.sh:export PATH=$PATH:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
The PATH assignment is there, plain to see.
And it comes from a file in "/etc/profile.d". Now a small bit of trivia is needed - knowing that the "whatever.d" folders are handy folders usually parsed from a whatever binary, and their contents is globbed sequentially.
So if the folder is /etc/profile.d
, I expect this trick to be turned out by /etc/profile
. Anyway, someone must meddle with "profile.d", so I can look for that:
# grep -r "profile\.d" /etc
And indeed I find, among several lines of output:
/etc/bash_completion.d/libreoffice.sh:# It is based on /etc/profile.d/complete.bash from SUSE Linux 10.1
/etc/profile:if [ -d /etc/profile.d ]; then
/etc/profile: for i in /etc/profile.d/*.sh; do
/etc/apparmor.d/snap/abstractions/bash: /etc/profile.dos r,
...
The second and third row are what I'm interested in. They say, "If there is a folder called /etc/profile.d, then; for each file ending in ".sh" in that folder, do...". This is exactly what I would have expected.
So, I can be confident that running /etc/profile
will do the trick.
And indeed it works:
ssh leonardo@aladdin ". /etc/profile; echo \$PATH"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/opt/android-sdk-linux/platform-tools:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
ssh ip '. ~/.profile; pyenv
'? – terdon May 19 '22 at 16:34