Unitech / pm2-deploy

Deploy part of PM2
http://pm2.keymetrics.io/docs/usage/deployment/
MIT License
178 stars 71 forks source link

post-deploy hook ignores PATH variable: bash: npm: command not found #41

Closed nleush closed 9 years ago

nleush commented 9 years ago

'npm', 'node' and 'pm2' works well from user 'ubuntu' on remote host. But when deploy, post-deploy hook can't see that commands using same user.

Also important thing: NVM is used to manage node, so all commands are behind /home/ubuntu/.nvm/v0.10.21/bin

Also tried:

sudo env PATH=$PATH:/home/ubuntu/.nvm/v0.10.21/bin pm2 startup linux -u ubuntu

and restarted server.

Log:

  ○ executing post-deploy `npm install && pm2 startOrRestart pm2.json`
  bash: npm: command not found
  post-deploy hook failed

Any suggestions? Thanks.

mansona commented 9 years ago

So i've just come across this same issue and for some reason the pm2 deploy command is ignoring both .bashrc files and .profile files for the user that it is connecting with. I assume this is because it's not creating a full bash session (or something)

To get this to work i edited the /etc/environment file to include the bin folder from my node install which in my case is: /usr/local/lib/iojs-v1.6.2-linux-x64/bin/

clux commented 9 years ago

The ssh connection from pm2 is not interactive. See: https://github.com/Unitech/pm2-deploy/issues/33

xpepermint commented 9 years ago

Same here.

xpepermint commented 9 years ago

Btw... the easiest way to resolve this is to open your .bashrc and comment out these lines:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

Pm2 is not using interactive ssh.

Unitech commented 9 years ago

Yes or just load nvm at the very beginning of your .bashrc

niftylettuce commented 8 years ago

Thanks for this @xpepermint! I've updated this in my guide here too, under the section "Set up SSH for SemaphoreCI": http://niftylettuce.com/posts/automated-node-app-ci-graceful-zerodowntime-github-pm2/

@Unitech Did you want to link to this comprehensive guide somewhere in the PM2 docs? I think it'd be helpful.

oney commented 8 years ago

Move the following lines to the top of .bashrc

export NVM_DIR="/root/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
hems commented 7 years ago

@oney indeed moving the "nvm" or "n" EXPORT path to the top of .bashrc sorted out this issue, but that's very inconvenient :S

farhanali3193 commented 3 years ago

I tried doing everything above but it didn't work. Probably because of my lack of understanding of concepts related to sym links. I fixed the issue by not using nvm. I just created a new ec2 instance and didn't install nvm. Instead I installed node and npm like so:

sudo apt update
sudo apt install nodejs npm

And this did it for me. For my appspec.yml, pm2 ecosystem file and other scripts, check out my answer: https://stackoverflow.com/a/68135733/14537951

Phobia-Cosmos commented 8 months ago

There any methods for Zsh?I've tried add the nvm export to the top of both ~/.bashrc and ~/.zshrc, it both doesn't work, really confused about the non-interactive mode.