0

I installed PM2 globally on Debian 10 (buster) using the following approach.

npm config set prefix ~/.local
echo 'export PATH=~/.local/bin/:$PATH' >> ~/.bashrc
source ~/.bashrc
npm -g install pm2

When I run ssh user@host pm2 ls, I get pm2: command not found.

It is my understanding that SSH commands run in non-interactive shells that do not source ~/.bashrc. Is this assumption correct?

Is there a way to work around this limitation without using an absolute path for pm2?

The above proof of concept is simplified. I am actually running a remote script that calls other scripts. Using an absolute path would make the scripts deployment-specific which I am trying to avoid.

sunknudsen
  • 6,356
  • 3
  • 39
  • 76

1 Answers1

0

Solve my problem thanks to https://stackoverflow.com/a/941995/4579271.

I had to add export PATH=~/.local/bin/:$PATH at the top of ~/.bashrc.

On Debian 10 (buster), ~/.bashrc includes instructions to return when shell is non-interactive.

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac
sunknudsen
  • 6,356
  • 3
  • 39
  • 76