The short answer
To upgrade npm to its latest version, you can use the following npm install command (effectively using npm to update npm):
$ npm install -g npm
Run in Warp
Alternatively, to update npm to a specific version, you can use the following syntax instead:
$ npm install -g npm@
Run in Warp
You can get the list of available npm versions on the official npmjs website.
Easily retrieve this command using Warp’s AI Command Search
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:
$ npm -v
Run in Warp
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:
$ which npm
Run in Warp
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:
$ nvm install-latest-npm
Run in Warp
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:
$ nvm ls
Run in Warp
Then switch to the desired Node.js version you want to use:
$ nvm use
Run in Warp
And finally update npm for this specific Node.js version:
$ nvm install-latest-npm
Run in Warp
Updating npm manually
To download and install npm manually using the official npmjs install script, you can run the following curl command:
$ curl -qL https://www.npmjs.com/install.sh | sh
Run in Warp
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:
{"engines": {
"npm": "7.24.2"
}
}
Run in Warp
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:
$ npx npm@ install [package …]
Run in Warp
For example:
$ npx [email protected] install
Run in Warp
Written by
Razvan Ludosanu
Founder, learnbackend.dev
Filed Under
Related Articles
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.
Install Dev Dependencies With npm
Learn how to install and update dev dependencies using the npm install command.
Clear npm Cache
Learn how to clear the npm cache on Linux, macOS, and Windows.
Re-Installing Npm
Learn how to reinstall Node.js and npm on macOS, Linux, and Windows using `curl`, `brew`, `apt`, `nvm`, and Node installer.
How To Reinstall Packages With Npm
Brief guide to reinstalling npm packages using npm
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
List Installed Npm Packages
Learn how to list globally and locally installed packages with npm, including their dependencies.