PM2 — Update the Utility

You already know how to use PM2 to start and stop processes. Honestly, installed tools, utilities and apps on your server to run your actual applications are one of the things you don’t want to touch that often and PM2 is no exception. Once everything is installed and running, you’re probably reducing the maintenance effort to almost zero to avoid downtime situations or further issues with breaking changes.

However, that doesn’t need to be the case with PM2. You can update the utility very easy and this article shows you the way to go!

PM2 Series Overview

Update PM2

Since PM2 is an NPM module including a command line utility, you can also use NPM for the update process. The first thing to do: version check. You can print the currently installed version of PM2 using the -v flag:

$ pm2 -v

We’ve installed PM2 in version 0.14.3 to demonstrate the update process. The latest stable version is as the time of this writing at 2.2.2 and we’re going to update to that latest version.

Check PM2’s GitHub release page for the latest version. If you’re running a version below the first one in the release list on GitHub, it may be time to update.

If there is a newer version available, we can update the PM2 version installed on your system via NPM. Use NPM’s install or update command to kick off the update process for PM2. Once the update finishes, you can go ahead and start the seamless update of PM2 itself.

Attention: This will stop all your running process, temporary dump the process list, update itself and restore the processes and afterwards restart them. The update itself is really fast. We experienced the update process to be finished within a second.

npm update -g pm2  
pm2 update  

The update procedure for PM2 will log the current status:

$ pm2 update
Be sure to have the latest version by doing `npm install pm2@latest -g` before doing this procedure.  
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] All processes have been stopped and deleted
[PM2] PM2 stopped
Process /Users/marcuspoehls/Dev/FutureStudio/homepage/server launched  
>>>>>>>>>> PM2 updated

│ App name │ id │ mode │ pid   │ status │ restart │ uptime │ memory     │ watching │
│ homepage │ 0  │ fork │ 49178 │ online │ 0       │ 0s     │ 8.508 MB   │ disabled │

Once the update finished, you’ll see the familiar process overview. Verify that every process was restored correctly and your apps are back online. That’s it. PM2 is up to date and you’re able to use the new features.

Verify if the desired version was installed correctly using pm2 -v:

$ pm2 -v

What Comes Next

The update process of PM2 is reduced to a minimum of effort. Actually, PM2 handles all the dump and restore execution of processes for you. The only thing to worry about is a short downtime.

Next week, we’ll show you how to restore processes managed by PM2 after system restarts. You can’t always babysit your server and want to build on robust tools relaunching your apps.

Additional Resources

Explore the Library

Find interesting tutorials and solutions for your problems.