Home Coding & Scripting Node Version Manager (nvm): A Developer’s Guide to Installing and Managing Node.js...

Node Version Manager (nvm): A Developer’s Guide to Installing and Managing Node.js Versions

266
0

When you first install Node.js, you usually just grab the latest version from the official website. That works fine for beginners. That works fine for beginners — and if that’s all you want right now and want to go to complexity later when you work with multiple projects, check out my step-by-step post here: Getting Started with Node.js: Setup and Hello World.

But once you start working on multiple projects, you’ll quickly hit a problem:

  • Project A might need Node 16
  • Project B might need Node 20

Updating Node.js globally could break one project while fixing another. That’s where Node Version Manager (nvm) comes in.


🛠️ What is nvm?

nvm is a tool that lets you install, manage, and switch between multiple versions of Node.js on the same computer.

Think of it like a remote control: you can switch Node.js versions with a single command.


🚀 Why Developers Use nvm

  • Multiple projects, different versions → no conflicts.
  • Experiment safely → test new Node.js features without breaking old code.
  • Team alignment → match the Node.js version your project specifies in package.json or .nvmrc.

📥 Step 1: Install nvm

On macOS

Run this in your terminal:

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

Then restart your terminal and verify:

command -v nvm

On Linux

Run the official install script (works on most distros):

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

Then reload your shell:

source ~/.bashrc

(or source ~/.zshrc if you use zsh).

Verify installation:

command -v nvm

💡 Note: Some Linux distributions (like Ubuntu) let you install nvm via their package manager (sudo apt install nvm), but this may give you an outdated version. Stick with the script unless you have a specific reason to use the package manager.


On Windows

If you’re on Windows, you’ll need a different version of nvm called nvm-windows. We’ve created a dedicated step-by-step guide for you here:

👉 Setup Node.js on Windows Using nvm


⚙️ Step 2: Basic nvm Commands

Install the latest LTS (recommended for most projects)

nvm install --lts

See which versions you have

nvm ls

Use a specific version

nvm use 20

Install a specific version (e.g., Node.js 16)

nvm install 16

Uninstall a version

nvm uninstall 16

Set a default version for new terminals

nvm alias default 20

🧑‍💻 Step 3: Real-World Example

Imagine you’re working on two projects:

  • Project A needs Node 16
  • Project B needs Node 20

You can switch instantly:

cd project-a
nvm use 16

cd ../project-b
nvm use 20

💡 Pro tip: Add a .nvmrc file inside a project with the version number:

16

Now when you run nvm use inside that folder, it automatically switches to Node 16.


🔄 Alternatives

  • nvm-windows → for Windows users.
  • fnm (Fast Node Manager) → faster, written in Rust.
  • Volta → great for pinned project versions.

But for most learners, nvm is the standard.


✅ Key Takeaway

If you want to grow as a developer, install Node.js using nvm. It makes your setup flexible, safe, and professional.


🔄 BONUS: Upgrading to the Latest LTS

One of the best parts of using nvm is how easy it is to keep Node.js up to date.

On Linux/macOS

# Install the latest LTS
nvm install --lts

# Switch to it
nvm use --lts

# (Optional) Make it the default for all new terminals
nvm alias default lts/*

On Windows (nvm-windows)

--lts isn’t supported the same way on Windows. Use lts (without the dashes):

# Install the latest LTS
nvm install lts

# Switch to it (works on recent nvm-windows)
nvm use lts

# Or switch by explicit version:
nvm use 22.20.0

Troubleshooting (Windows):

  • If nvm use --lts fails with a 404 or similar, drop the dashes: nvm use lts.
  • If nvm use lts doesn’t pick up, switch by explicit version: nvm use 22.20.0.

Note: nvm-windows doesn’t support alias default. If you want a version to be active in every new terminal, rerun nvm use <version> (or add it to your shell startup).


✅ After upgrading, confirm:

node -v
npm -v

You should now see the latest LTS (e.g., v22.20.0).

💡 You don’t need to uninstall older versions—keep them for compatibility and switch with nvm use <version> anytime.

Previous articleUnderstanding the Node.js Runtime
Next articleSetup Node.js on Windows Using nvm
Heartin Kanikathottu
As a seasoned Cloud and Security Architect, I’ve led transformative initiatives in key roles, including Vice President at Morgan Stanley, Principal Architect at Societe Generale, and Tech Lead & Cloud Security Architect at VMware, among others. I’m also an internationally published author with multiple books available on platforms like Amazon and O'Reilly. Notably, one of my books was recognized as the 8th best cloud computing book of all time in 2020, reflecting the impact of my contributions to the field. With over 15 professional certifications from providers such as Microsoft (Azure), Amazon (AWS), Oracle (Java), Pivotal (Spring), and IBM, I bring a wealth of expertise to my work. Academically, I hold dual Master’s degrees in Cloud Computing and Data Analytics. I’m passionate about sharing knowledge and mentoring others, which is why I actively speak at global technical forums such as Tech Opportunities Fest at Platform Calgary, Google's Kubernetes Meetup, Java User Group, Elasticsearch Meetup, and the Agile India Conference.

LEAVE A REPLY

Please enter your comment!
Please enter your name here