How to update Node.js and npm to the latest version?

Node.js version update is quite easy. It is recommended to use nvm for Node.js version update. nvm stands for node version manager.

The following are the steps to update Node.js version:

Update Node.js version:

$ nvm install <version>
$ nvm use <version>

Let’s say we want to install Node.js version 16.15.1, we need to do the following:

$ nvm install 16.15.1;
$ nvm use 16.15.1;

// To check latest Node.js version try this command: 
$ node -v

Update npm version:

Updating npm version is quite easy too. We can run the following command to update npm.

$ npm install npm@latest -g

// To check latest npm version try this command: 
$ npm -v
Reference: