PM2 command not found

后端 未结 8 439
夕颜
夕颜 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:13

    PM2 the process manager for Node.js applications. PM2 basically manages applications (run them in the background as a service). So this is how we install PM2 globally with sudo permissions account

    sudo npm install -g pm2
    

    The -g option tells npm to install the module globally, so that it's available system-wide. Once this is installed, check the installed path as:

    whereis pm2
    pm2: /opt/node/bin/pm2 /opt/node/lib/node_modules/pm2/bin/pm2
    

    Now, we need to add this path in startup bash script. Add add the following line anywhere in ~/.bashrc file.

    export PATH=$PATH:/opt/node/lib/node_modules/pm2/bin
    

    Now re-login or source the bash script as follows(so that bash script runs and path is set)

     source ~/.bashrc
    

    and now it should run. check the status of pm2

    pm2 status
    
    0 讨论(0)
  • 2020-12-24 12:19

    If you used nvm to install node and npm, install pm2 for normal user.

    run as root:

    sudo su
    vim ~/.bashrc
    

    append below code, change NVM_DIR to you normal user's home folder:

    export NVM_DIR="/home/[PLEASE CHANGE]/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  
    # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. 
    "$NVM_DIR/bash_completion"  
    # This loads nvm bash_completion
    

    at last :

    source ~/.bashrc
    
    0 讨论(0)
提交回复
热议问题