'Github Actions pm2: command not found
I am trying to auto-deploy the project and npm commands run perfectly but when it goes to a line where pm2 restarts the specific projects, then actions fails.
GitHub Actions Error:
GitHub Action .yml file content:
Solution 1:[1]
NOTE: This solution is applicable only when you are using an NVM to manage node.js versions
The issue is because of the missing symbolic link for the node and the pm2, here are the commands that you can use to create a symbolic link:
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/node" "/usr/local/bin/node"
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/npm" "/usr/local/bin/npm"
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/pm2" "/usr/local/bin/pm2"
Solution 2:[2]
lo que pasa es que seguro instalaste todo por NVM lo cual no esta mal, pero para que puedas utilizar pm2 dentro del action de github, lo que tienes que realizar es.
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/node" "/usr/local/bin/node"
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/npm" "/usr/local/bin/npm"
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/pm2" "/usr/local/bin/pm2"
despues de la intalacion para que asi puedas utilizar con sudo el pm2 y de esa forma te funcionara sin problemas
Solution 3:[3]
I run into the same issue.
So basically, pm2
is not installed. I found it a bit strange as in my VPS, the pm2 is installed and is running perfectly.
The way I got around with it was to create a bash script in the root directory of my project: pm2_runner.sh
, within this file I added:
#!/bin/bash
if ! type pm2 > /dev/null
then
sudo npm install -g pm2 && pm2 start ./app.js --name my_project_name
else
pm2 restart my_project_name
fi
Then in my .yml file inside .github/workflow/
, instead of writing:
- run: pm2 restart my_project_name
I added:
- run: chmod +x ./pm2_runner.sh
- run: bash ./pm2_runner.sh
It installed pm2
globally without requesting sudo passord since sudo in github actions runs using passwordless.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kishor Patidar |
Solution 2 | alvaro morales cabalero |
Solution 3 | Horacio Soldman |