ssh-action
ssh-action copied to clipboard
Not able to execute npm global packages commands like pm2, nodemon
Not able to execute any npm global package commands like pm2 , nodemon etc..
in remote ssh server i configured the global package directory as per instruction https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
already install package like pm2 and nodemon
npm install pm2 -g
npm install nodemon -g
after installation
pm2 -v
5.2.0
But getting Error in github action while executing command via ssh-action
in .yaml file
- name: executing ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_SERVER_IP}}
username: ${{ secrets.SSH_USER_NAME }}
key: ${{secrets.SSH_KEY}}
script: |
node -v
pm2 -v
but getting following error
======CMD======
node -v
pm2 -v
======END======
out: v16.14.0
err: bash: line 1: pm2: command not found
This happens because npm-global was not loaded in path properly while using ssh-action
I followed the instruction from here stackoverflow answer
npm config get prefix
Then this will be return some thing like this: in my case
/your_user/.npm-global
Copy this path, and add the /bin in the end -> /your_user/npm-global/bin
Export the path in your script section like following
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_SERVER_IP}}
username: ${{ secrets.SSH_USER_NAME }}
key: ${{secrets.SSH_KEY}}
script: |
PATH=$PATH:/${{secrets.SSH_USER_NAME}}/.npm-global/bin
pm2 -v
now it outputs 5.2.0
thanks it works for me even I'm using nvm
For node version v18.14.0, .npm-global folder no longer existed.
PATH=$PATH:/home/${{secrets.SSH_USER_NAME}}/.nvm/versions/node/v18.14.0/bin
For people who used volta, it's
export PATH=$PATH:/home/${{ secrets.SSH_USER_NAME }}/.volta/tools/image/node/18.16.0/bin