How can I update Node.js and NPM to their latest versions?

Better Stack Team
Updated on March 11, 2024

There are several ways to update Node.js to its latest version. Here are three methods:

Updating Node.js

Using NPM

You can use NPM to update Node.js by installing the n package, which will be used to interactively manage node versions on your device. Here are the steps:

 
npm cache clean -f
npm install -g n
n latest

The first command clears the NPM cache. The second command installs the n package globally, which manages the Node versions at the root. The third command installs the latest version of Node.js.

Using NVM

NVM stands for Node Version Manager, and it helps you manage your Node Versions. With NVM, you can install Node versions and specify the version of Node that a project uses. NVM makes it easy to test projects across various Node versions. Here is how to update a Node Version with NVM:

 
nvm install node --reinstall-packages-from=node

This command installs the latest version of Node.js.

Downloading from the Node.js website

You can also download the latest version of Node.js from the Node.js website. On it, you can find the latest and long-term support versions for your device.

Updating NPM

You can update NPM to its latest version by running the following command:

 
npm install -g npm@latest

This command installs the latest version of NPM globally.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github