How can I update NodeJS and NPM to the next versions?


I just installed Node.js and npm (for additional modules).

How can I update Node.js and the modules which I'm using to the latest versions?

Can npm do it, or do I have to remove and reinstall Node.js and npm to get the next versions?

I followed this steps in the npm section.

5/13/2020 2:44:17 AM

I found this really neat way of updating node on David Walsh's blog, you can do it by installing n:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

It will install the current stable version of node.

EDIT: Please don't use n anymore. I recommend using nvm. You can simply install stable by following the commands below:

nvm ls-remote
nvm install <version> 
nvm use <version>

Updating npm is easy:

npm install [email protected] -g

I understand this question is for Linux machine but just in case anybody is looking for a Windows solution, just go to the Node.js site, click the download button on the homepage and execute the installer program.

Thankfully it took care of everything and with a few clicks of 'Next' button I got the latest 0.8.15 Node.js version running on my Windows 7 machine.


As you may already know, npm is currently bundled with node.js. It means that if you have installed node.js, you've already installed npm as well.

Also, pay attention to the node.js and npm release versions table that shows us approximate versions compatibility. Sometimes, versions discrepancy may cause incompatibility errors.

So, if you're a developer, it's kinda "best practice" to manage your development environment using one of the node.js version managers.

Here is a list and usage notes of some of the most popular:

Homebrew (macOS)

If you're on macOS, you can use Homebrew.

Actually, it's not just a node.js version manager.

To install Homebrew to your Mac:

$ ruby -e "$(curl -fsSL"

To install node.js and npm using Homebrew, run:

$ brew install node

Later, you will be able to update them using:

$ brew update && brew upgrade node

Also, you can switch between node.js versions as well:

$ brew switch node 0.10.26

npm will be upgraded/downgraded automatically.

n (macOS, Linux)

n is most likely to rvm (Ruby Version Manager), and is used to manage node.js and npm versions simultaneously. It is written on pure Linux shell, and available as an npm module. So, if you already have any node.js version installed, you can install/update the n package through npm:

$ npm install -g n

Downloading, installing and switching to node.js and npm versions is as easy as:

$ n 0.10.26
$ n 0.8.17
$ n 0.9.6

To download, install, and switch to the latest official release, use:

$ n latest

To download, install, and switch to the latest stable official release, use:

$ n stable

To switch to the previously active version (aka $ cd -), use:

$ n prev

If you want to see the list of installed node.js versions, just run n from your command line. The output will be something like the following:

$ n

• 0.8.17

Where the dot (•) means that it's a currently active version. To select another node.js version from the list, use Up/Down arrow keys and activate using the Enter key.

To list the versions available to install:

$ n lsr

nvm (macOS, Linux)

nvm is also like rvm, even the command names and usage are very similar.

To install nvm you can use the installation script (requires git) using cURL:

$ curl | sh

or wget:

$ wget -qO- | sh

To download and install a specific node.js and npm version, use:

$ nvm install 0.10

Then, you can switch to the installed version, using:

$ nvm use 0.10

Also, you can create the .nvmrc file containing the version number, then switch to the specified version using the following command:

$ nvm use

To see the list of installed node.js versions, use:

$ nvm ls

To list the versions available to install:

$ nvm ls-remote

nvm-windows (Windows)

nvm-windows is a node.js version management utility for Windows, ironically written in Go.

It is not the same thing as nvm. However, the usage as a node.js version manager is very similar.

To install nvm-windows, it is required to uninstall any existing versions of node.js and npm beforehand. Then, download and run the latest installer from releases.

To upgrade nvm-windows, run the new installer. It will safely overwrite the files it needs to update without touching your node.js installations.

nvm-windows runs in an Admin shell. You'll need to start Powershell or Command Prompt as Administrator to use nvm-windows.

Before using, you may also need to enable nvm-windows with the following command:

C:\> nvm on

To download and install a specific node.js and npm version, use:

C:\> nvm install 0.12

Then, you can switch to the installed version, using:

C:\> nvm use 0.12

If you want to see the list of installed node.js versions, use:

C:\> nvm list

To list the versions available to install:

C:\> nvm list available

First check your NPM version

npm -v

1) Update NPM to current version:

View curent NPM version:

npm view npm version

Update npm to current version:

npm i -g npm

2) List all available NPM versions and make a custom install/update/roll-back

View all versions including "alpha", "beta" and "rc" (release candidate)

npm view npm versions --json

Reinstall NPM to a specific version chosen from the versions list - for example to 5.0.3

npm i -g [email protected]
  • Installing one version will automatically remove the one currently installed.

  • For Linux and iOS prepend commands with sudo