Quick Summary
Have you ever found need to test your app with a different version of Node? Well, NVM (Node Version Manager) is here to make that process super easy and hassle-free.
In this blog post, we’ll guide you through the steps to install NVM, how to switch between different Node versions, and help you avoid common setup mistake, step-by-step!
Introduction
Let’s be honest, Node.js is constantly changing. And sometimes, your go-to library just doesn’t play nice with the version you’re using. If you’re juggling multiple projects that each have their own Node requirements, that’s where NVM comes to the rescue.
In this blog, we’re going to guide you through the process of installing and using NVM, and we’ll also dive into why it’s an essential tool for every developer’s toolkit.
What is NVM?
NVM, or Node Version Manager, is a handy command-line tool that makes it super easy to install, use and switch between various versions of Node.js.
It works its magic by tweaking your environment variables behind the scenes, so you don’t have to worry about mess with system-level installations.
Why You Need NVM
Whether you’re a backend developer or a full-stack developer, here’s why NVM should be your go to tool:
Multiple Projects: Effortlessly manage different Node versions for each of your applications.
Legacy Support: Keep your old code running smoothly without messing up your system installation.
Speed & Simplicity: Switch between versions with just a single command.
“One tool to manage them all.” – probably what Tolkien would say if he used Node.
Installing NVM (Mac/Linux)
You can easily install NVM by using either a cURL or Wget script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
After you’ve installed it, make sure to restart your terminal or simply run:
source ~/.nvm/nvm.sh
Great! Now you can check if it's installed by running nvm --version
.
Installing NVM (Windows
If you're using Windows, there's a dedicated version of NVM called nvm-windows.
To get started, download the latest .zip
or .exe
installer.
Just run it and follow the prompts.
Once it's installed, you can use nvm install <version>
just like you would on Mac or Linux!
Basic NVM Commands
nvm install <version>
: Installs a specific Node.js version
nvm use <version>
: Switches to that version
nvm list
or nvm ls
: Lists all installed versions
nvm uninstall <version>
: Removes a version from your system
Example:-
nvm install 18
nvm use 18
How to Switch Between Node Versions
Let’s say you’ve installed Node 16 and 18.
Switching is as simple as:
nvm use 16
This command sets the current terminal session to use Node 16.
Want to make it default?
nvm alias default 16
Now every new terminal session will use Node 16.
Managing Project-Specific Node Versions
You can create an .nvmrc
file in your project root:
16.20.1
Then, inside the directory:
nvm use
It will automatically pick the version listed in.nvmrc
. Perfect for teams and CI/CD.
Pro Tip: Add .nvmrc
to your Git repo to maintain version consistency across environments.
Common Errors and Fixes
nvm: command not found
: Run source ~/.nvm/nvm.sh
or restart terminal
Node version not switching : Check if another Node is globally installed via Homebrew or system package manager
.nvmrc
ignored : Make sure you’re inside the project folder when using nvm use
Conclusion
There you have it all, your ultimate guide to effortlessly switching Node versions like a pro.
Whether you’re diving into an enterprise application or just a weekend side project, NVM ensures your workflow stays clean, speedy and adaptable.
Are you Looking for expert help managing your Node.js stack or switching environments cleanly? Our backend team is ready to assist. Hire Node.js developers who know how to keep things smooth and scalable.