How to Upgrade (or Downgrade) Node.js Using npm

By Cory LaViska on May 29, 2019

Need to update your version of Node.js? Here's how you can upgrade or downgrade from the command line using npm.

Node.js logoAs you may know, Surreal CMS used to be a PHP app but I recently rebuilt it in Vue.js + Node.js. Being able to switch between Node versions quickly was really helpful while developing, so here are my notes for managing which version is currently installed.

Big News, by the way! I've made Surreal CMS free for personal, educational, and non-profit websites. 👏

Determining your Node version

First off, let's figure out which version of Node is currently installed.

node -v

The version number displayed is the one that's currently active on your machine. Now, let's install a program called n that will let us easily switch between Node versions.

sudo npm install -g n

Upgrading to the latest stable version

Once n is installed, this simple command will update you to the latest stable version of Node.

sudo n stable

Changing to a specific version

If you need a specific version, simply specify the version number you want like this.

sudo n 10.16.0

You can find a full list of releases here.

As you can see, n is a really handy program that makes switching between Node versions effortless. It's worth keeping around if you do any serious development with Node.js.