Ubuntu uses pm2 to automate the deployment of nodejs service error: pm2 commond not found?

ubuntu uses pm2 to automate the deployment of nodejs services: pm2 commond not found?

echsystem.json file:

{
  "apps": [
    {
      "name": "commic",
      "script": "app.js",
      "env": {
        "COMMON_VARIABLE": "true"
      },
      "env_production": {
        "NODE_ENV": "production"
      }
    }
  ],
  "deploy": {
    "production": {
      "user": "xsy",
      "host": ["120.78.165.227"],
      "port": "19999",
      "ref": "origin/master",
      "repo": "git@gitee.com:xiasiyong/cmmic.git",
      "path": "/home/xsy/www/comic/production",
      "ssh_options": "StrictHostKeyChecking=no",
      "post-deploy": "pm2 startOrRestart ecosystem.json --env production",
      "env": {
        "NODE_ENV": "production"
      }
    }
  }
}

execute on your own computer: pm2 deploy ecosystem.json production setup, succeeded

--> Deploying to production environment
--> on host 120.78.165.227
   hook pre-setup
   running setup
   cloning git@gitee.com:xiasiyong/cmmic.git
   full fetch
Cloning into "/home/xsy/www/comic/production/source"...
   hook post-setup
   setup complete
--> Success

when publishing: pm2 deploy ecosystem.json production, reported an error

xiasiyongdeMacBook-Pro:cmmic xiasiyong$ pm2 deploy ecosystem.json production
--> Deploying to production environment
--> on host 120.78.165.227
   deploying origin/master
   executing pre-deploy-local
   hook pre-deploy
   fetching updates
   full fetch
Fetching origin
   resetting HEAD to origin/master
HEAD is now at de8333a 11
   executing post-deploy `export NODE_ENV=production && pm2 startOrRestart ecosystem.json --env production`
bash: pm2: command not found

  post-deploy hook failed

Deploy failed

my server is Aliyun, ubuntu 14.04. Is it okay to run PM2-v on the server side?

xsy@iZwz9isotv99f3eth4ow92Z:~$ pm2 -v
2.7.2

executing commands under the folder directory corresponding to the server is OK again,

clipboard.png

my younger brother is ashamed and has no result for a long time. I would like to ask all the great gods, what is wrong with me?

Mar.07,2021

the search path is incorrect.

sudo npm i -g pm2

the same question, has the landlord solved the same problem


? How to solve it? I have the same problem

Menu