Score:0

Why can't ssh run rbenv in the shell?

ch flag

I'm trying to run a bash script on a remote server to install ruby via rbenv.

#!/bin/bash
# ssh [email protected] 'bash -s' < configure.sh

echo "ruby 3.2.1"
rbenv install 3.2.1 --verbose
rbenv global 3.2.1

On a remote server rbenv is already installed for the user deploy. If I log into that server, it runs OK.

❯ ssh [email protected]
deploy@ubuntu-focal:~$ rbenv
rbenv 1.2.0-59-g0704e65
Usage: rbenv <command> [<args>...]

But if we try to run the command over ssh, it can't be found.

❯ ssh [email protected] "rbenv"
bash: rbenv: command not found

Same problem with the script.

❯ ssh [email protected] 'bash -s' < configure.sh
ruby 3.2.1
bash: line 5: rbenv: command not found
bash: line 6: rbenv: command not found
bash: line 7: ruby: command not found
bash: line 9: gem: command not found
bash: line 10: gem: command not found
Score:2
ar flag

In short, $PATH is not set.

Bash, when started in interactive mode or as login shell, reads a few config files, such as .profile and .bashrc:

--noprofile
  Do not read either the system-wide startup file /etc/profile  or
  any   of  the  personal  initialization  files  ~/.bash_profile,
  ~/.bash_login, or ~/.profile.   By  default,  bash  reads  these
  files  when  it  is invoked as a login shell (see INVOCATION be-
  low).

--norc Do  not  read  and  execute  the  personal  initialization  file
       ~/.bashrc if the shell is interactive.  This option is on by de-
       fault if the shell is invoked as sh.

From man bash. You start a non-login, non-interactive shell.

Either, your script should:

  1. source ~/.bashrc
  2. Specify $PATH on it's own
  3. Use absolute paths
port5432 avatar
ch flag
Thank you @vidarlo, the `source` didn't work, but setting the `$PATH` did.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.