Use nvm install and nvm use to upgrade Node.js versions easily. NVM allows seamless switching between different Node environments.

Problem

Upgrading Node.js manually can cause compatibility issues or system wide conflicts. NVM is the safer way to manage and switch between Node versions.

Solution

Follow these steps to upgrade Node.js using NVM (Node Version Manager):

1. List Installed Node Versions

bash

nvm ls

This shows all the versions installed via NVM.

2. List all versions

bash

nvm ls-remote

This shows all the Node.js versions available for install.

3. Install the latest

bash

nvm install node

This installs the latest Current version of Node.js.

Or to install the latest LTS version:

bash

nvm install –lts

Also Read: How To Update Node JS To Latest Version

4. Set default Node version

bash

nvm use <version>nvm alias default <version>

Example:

bash

nvm use 22.17.0nvm alias default 22.17.0

5. Verify Node and npm

bash

node -vnpm -v

Conclusion

NVM is the best way to upgrade Node.js. It allows version switching and protects your environment from system wide conflicts.