PM2 command not found

后端 未结 8 438
夕颜
夕颜 2020-12-24 11:37

I installed node.js and npm to my centOS 7 server. But i have problems with pm2. Actually real problem is i don\'t have experiences in linux and i don\'t know how to change

相关标签:
8条回答
  • 2020-12-24 12:02

    Install PM2 globally and run everything as a root user

    sudo apt-get install npm
    sudo npm i -g pm2
    sudo ln -s /usr/bin/nodejs /usr/bin/node
    

    You are good to go

    0 讨论(0)
  • 2020-12-24 12:03

    Install PM2 globally:

    run as root:

    npm i -g pm2
    

    or if user is sudo-er

    sudo npm i -g pm2
    

    and then go back to user (or stay in root if it was created by root user) and run it:

    pm2 start server.js
    
    0 讨论(0)
  • 2020-12-24 12:03

    This option helped me:

    sudo npm i -g pm2
    
    0 讨论(0)
  • 2020-12-24 12:04

    If you install through NPM and it does not work, you can create a symbolic link as well :

    ln -s /<your-user>/.npm-global/lib/node_modules/pm2/bin/pm2 /usr/bin/pm2
    

    After that, you're going to be able to call:

    pm2
    
    0 讨论(0)
  • 2020-12-24 12:09
    sudo npm i -g pm2
    

    It worked for me.

    0 讨论(0)
  • 2020-12-24 12:12

    Error on using port 80 with PM2?

    The wrong way of going about this is trying to run with sudo.

    The correct way of doing this would be to login as root sudo su, then run pm2 start app.js --name "whatever" --watch.

    Logging in as root, there's no need to configure any bashrc or profile files. However, as root, the script can use nodejs's exec() function dangerously. To avoid this, do the root stuff first with your script, then lower your privilege after some timeout:

    // I use port 80 first.. at this point the script's UID is root.
    
    app.listen(80);
    
    // After 2 seconds we switch to UID `azureuser`, which obviously isn't root anymore.
    
    setTimeout(function() {
      process.setuid("azureuser");
    }, 2000);
    
    0 讨论(0)
提交回复
热议问题