Correct way to update PM2 after updating Node.js

After updating Node.js from v10.16 to v10.32 PM2 was not detected, however it worked fine when checked with ps aux. Even when the system was rebooted, the PM2 functioned correctly, although the manual commands of the PM2 resulted in the following type of error.

pm2 list pm2: command not found

Switching Node.js back to 10.16 and PM2 commands were available again. Fyi PM2 was originally installed at version 10.16.

While in version 10.32 tried to install PM2 with npm install pm2 -g but she had to use npm install pm2 -g --unsafe-perm to get it working.

Node.js v10.16 is now running PM2 v10.1. Node.js v10.32 is now running PM2 v10.8.

Is this the correct method to keep PM2 versions in sync and work with Node updates / changes? Should this happen after installing every new version of Node?

+4


source to share


3 answers


When you switch node versions, you switch packages too, so you need to reinstall pm2 to node update. Fortunately, this doesn't happen very often.

You can do a shell sript to do this in one go.



For an insecure thing, this only happens if you set pm2 as root. This makes sense if you think pm2 has quite a lot of control over your machine processes.

+1


source


There seems to be no way without reinstalling PM2 after updating Node: --(

$ nvm install 6.11.3 --reinstall-packages-from=6.11.2 && nvm alias default 6.11.3
$ nvm uninstall 6.11.2
$ pm2 updatePM2 # Update in memory pm2
$ pm2 startup
$ nano /etc/init.d/pm2-init.sh  # Wrong path :-(

      



But reinstalling pm2 is not enough, some things are still broken, even if they work, the logs no longer work in real time, for example My fix:

$ rm -rf /root/.pm2
$ pm2 reload pm2.json --env production
$ pm2 startup ubuntu

      

0


source


Don't forget to recompile the packages after updating your node.js version:

cd /to/root/of/your/project
npm rebuild
npm i -g pm2 && pm2 update

# here 0 and dist/main.js change for your project
pm2 delete 0 && pm2 start dist/main.js

      

0


source







All Articles