Why NVM is Tremendously Helpful for Web Developers

If you are working on Node.js ecosystem then probably you’ve heard about node version manager or NVM.

Today, we will see why this exists and why you should care about learning it.

What is NVM?

According to the official docs,

nvm allows you to quickly install and use different versions of Node.js via the command line.

Apart from that, it also keeps you away from many errors.

The problem at hand

Ever encountered the EACCESS error when you tried to install some global npm package?

npm install -g some-package

I bet you have! But what’s the solution? Some StackOverflow answers will suggest you use sudo . Which is a very very bad idea and can lead you to more problems.

The official npm docs suggest that we use node version manager (nvm) to resolve this issue.

Install NVM

If you are using Linux run the following command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

If it’s successful you can check the version:

command -v nvm

You may have to close your terminal and reopen it again.

Install the Latest Version of Node.js

If we want to install the latest version of the node we can run the following command:

nvm install node

At the time of writing this article, the latest version of the Node.js is v17.3.0.

Install Specific Version of Node.js

At the time of writing this article, the latest version of Node.js is 16.13.1 . If we want to install this specific version:

nvm install 16.13.1

Check the installed versions

If you want to see the list of versions installed on your machine run the following command:

nvm ls

This will show the versions on your machine.

result of npm ls

Use a specific version of the node

Now let’s say you have multiple versions of the node installed on your machine. And you want to switch between them. Maybe you want to work on a legacy app that uses Node.js 14.

You can just run:

nvm use 14

You can check the version of the node by running the following command:

node -v

And now you are using Node 14.

version switch of node

Install the Latest Version of npm

You can install the latest version of npm for the version run the following command:

nvm install-latest-npm

And check the version:

npm --version

So essentially you can have multiple versions of npm on your machine now!

How cool is that?

Final Notes

These tools are here to make our lives easier. Let’s take full advantage of them.

Hope you learned something new today. Have a great day!

Have something to say? Get in touch with me via LinkedIn

Share this post

Read more articles...


NodeJS Security Best Practices


React useState hook from scratch


How to Sanitize Data in React


Dockerizing a basic Node.js/Nest.js application

Profile Image

Who I am

Hi, I amMohammad Faisal, A full-stack software engineer @Cruise , working remotely from a small but beautiful country named Bangladesh.

I am most experienced inReactJS,NodeJS andAWS

Buy Me a Coffee Widget