How To Update NPM

Razvan Ludosanu
Razvan LudosanuFounder, learnbackend.dev
Published: January 31, 2024

The short answer

To upgrade npm to its latest version, you can use the following npm install command (effectively using npm to update npm):

Bash
$ npm install -g npm

Alternatively, to update npm to a specific version, you can use the following syntax instead:

Bash
$ npm install -g npm@

You can get the list of available npm versions on the official npmjs website.

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Search feature:

Entering update npm in the AI Command Search will prompt an npm command that can then quickly be inserted into your shell by doing CMD+ENTER.

Checking the current npm version

To check the current version of npm in use, you can use the -v flag (short for version) as follows:

Bash
$ npm -v

On the other hand, if you have multiple versions of npm installed and want to find out which npm binary is in use, you can run the following command:

Bash
$ which npm

Updating npm using nvm

If you are using nvm as your Node.js version manager, you can update npm to the latest version supported by your current Node.js distribution in use with the following nvm command:

Bash
$ nvm install-latest-npm

Updating npm for a specific Node.js version

If you have multiple versions of Node.js installed on your system, you can first list them:

Bash
$ nvm ls

Then switch to the desired Node.js version you want to use:

Bash
$ nvm use

And finally update npm for this specific Node.js version:

Bash
$ nvm install-latest-npm

Updating npm manually

To download and install npm manually using the official npmjs install script, you can run the following curl command:

Bash
$ curl -qL https://www.npmjs.com/install.sh | sh

Note that the npmjs documentation strongly recommends you download and install npm using a tool like nvm; see https://docs.npmjs.com/downloading-and-installing-node-js-and-npm for more details.

Change to a specific npm version using npx to install a package

If your installed version of npm differs from the required npm version specified in the package.json file of your project:

Bash
{"engines": {
    "npm": "7.24.2"
  }
}

You can use the following npx command, which will execute the npm install command using the specified npm version, without actually updating the currently installed version of npm on your local machine.

To download and install npm manually using the official npmjs install script, you can run the following curl command:

Bash
$ npx npm@  install [package …]

For example:

Bash
$ npx npm@9.6.6 install
Written by
Razvan Ludosanu
Razvan LudosanuFounder, learnbackend.dev
Filed under

Related articles


How To Reinstall Packages With Npm

Brief guide to reinstalling npm packages using npm

List Installed Npm Packages

Learn how to list globally and locally installed packages with npm, including their dependencies.

Check Npm Package Version

Check an npm package version within your project

Install NPM Packages From GitHub

Check an npm package version within your project

Clear npm Cache

Learn how to clear the npm cache on Linux, macOS, and Windows.

Install Dev Dependencies With npm

Learn how to install and update dev dependencies using the npm install command.

Removing npm Packages

Learn how to remove packages locally, globally, and from the registry using the npm uninstall command.

Execute Packages With npx And npm

Discover the power of npm's npx tool, a developer's best friend for running packages without global installs.

Re-Installing Npm

Learn how to reinstall Node.js and npm on macOS, Linux, and Windows using `curl`, `brew`, `apt`, `nvm`, and Node installer.