How to change the version of NPM using NVM

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
2 min

banner

# How to change the version of NPM using NVM

Use the nvm install-latest-npm command to change the version of npm using nvm.

The command updates your npm version to the latest supported npm version by the current Node.js version.

shell
nvm install-latest-npm # ๐Ÿ‘‡๏ธ same as above nvm install --latest-npm

change version of npm with nvm

The nvm install-latest-npm updates your npm version to the latest supported npm version by the current Node.js version.

You can use the npm -v command to check your version of npm.

shell
# ๐Ÿ‘‡๏ธ check the version of npm npm -v # ๐Ÿ‘‡๏ธ check version of Node.js node -v

check npm and node versions

# Installing a specific version of npm

If you want to install a specific version of npm, you have to use the npm install command with a version modifier.

shell
npm install -g npm@7.7.2 npm install -g npm@8.11.0

You can use the npm view npm versions command to list all versions of npm.

shell
npm view npm versions

If you want to show the latest npm version, use the npm view npm version command.

shell
npm view npm version

Alternatively, you can update npm to the latest version with the following command.

shell
npm install -g npm@latest

update npm to latest version

You might have to prefix the command with sudo (macOS and Linux) or open CMD as an administrator (Windows) if you get a permissions error.

# Installing the latest version of Node.js

If you want to install the latest version of Node.js, use the nvm install node command.

shell
# ๐Ÿ‘‡๏ธ for macOS and Linux nvm install node # ๐Ÿ‘‡๏ธ for Windows nvm install latest

nvm install latest

node is an alias for the latest version.

If you want to use this version, issue the nvm use node command or the command from the end of your installation message.

shell
# ๐Ÿ‘‡๏ธ for macOS and Linux nvm use node # ๐Ÿ‘‡๏ธ for Windows nvm use latest

nvm use node latest version

If you want to install the long-term supported version or another version, first use the nvm ls-remote or nvm list available command.

PowerShell
# ๐Ÿ‘‡๏ธ for macOS and Linux nvm ls-remote # ๐Ÿ‘‡๏ธ for Windows nvm list available

nvm ls remote

Currently the long-term supported version is 18.12.1, so I can install the specific version with the following command.

PowerShell
# ๐Ÿ‘‡๏ธ install specific version nvm install 18.12.1

To use the specific version, issue the nvm use command.

PowerShell
# ๐Ÿ‘‡๏ธ use specific version nvm use 18.12.1

You can use the nvm ls command to check which nvm versions you have installed and which is the currently active version.

PowerShell
nvm ls node --version npm --version

nvm list installed versions

If you get a permissions error when issuing an nvm command, you have to prefix the command with sudo (macOS and Linux) or start PowerShell or CMD as an administrator (Windows) and rerun the command.

You can view all of the available nvm commands in this section of the package's GitHub repository.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev