Terminus
How To Update NPM

How To Update NPM

The short answer

To upgrade [.inline-code]npm[.inline-code] to its latest version, you can use the following [.inline-code]npm install[.inline-code] command (effectively using [.inline-code]npm[.inline-code] to update [.inline-code]npm[.inline-code]):

 $ npm install -g npm

Alternatively, to update [.inline-code]npm[.inline-code] to a specific version, you can use the following syntax instead:

 $ npm install -g npm@

You can get the list of available [.inline-code]npm[.inline-code] versions on the official npmjs website.

[#easily-recall-with-ai]Easily retrieve this command using Warp’s AI Command Search[#easily-recall-with-ai]

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

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

[#check-current-npm-version]Checking the current npm version[#check-current-npm-version]

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

 $ npm -v

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

 $ which npm

[#update-using-nvm]Updating [.inline-code]npm[.inline-code] using [.inline-code]nvm[.inline-code][#update-using-nvm]

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

 $ nvm install-latest-npm

[#for-specific-version]Updating [.inline-code]npm[.inline-code] for a specific Node.js version[#for-specific-version]

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

 $ nvm ls

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

 $ nvm use 

And finally update [.inline-code]npm[.inline-code] for this specific Node.js version:

 $ nvm install-latest-npm

[#updating-npm-manually]Updating [.inline-code]npm[.inline-code] manually [#updating-npm-manually]

To download and install [.inline-code]npm[.inline-code] manually using the official npmjs install script, you can run the following [.inline-code]curl[.inline-code] command:

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

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

[#package-specific]Change to a specific [.inline-code]npm[.inline-code] version using [.inline-code]npx[.inline-code] to install a package[#package-specific]

If your installed version of [.inline-code]npm[.inline-code] differs from the required [.inline-code]npm[.inline-code] version specified in the [.inline-code]package.json[.inline-code] file of your project:

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

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

To download and install [.inline-code]npm[.inline-code] manually using the official npmjs install script, you can run the following [.inline-code]curl[.inline-code] command:

 $ npx npm@  install [package …]

For example:

 $ npx npm@9.6.6 install