Quick Guide: Installing and Automating Node.js Versions with nvm


Quick Guide: Installing and Automating Node.js Versions with nvm

nvm-sh/nvm

2025-10-15

Here's a friendly, detailed explanation of how it can help you, along with installation steps and code examples.

As engineers, we often work on multiple projects simultaneously. These projects rarely use the exact same tool versions, and this is where nvm shines.

Different projects may require different major, minor, or patch versions of Node.js.

The Problem
Your legacy project might only work reliably on Node 14, but your new project needs the latest features in Node 20. Without nvm, constantly switching and managing these versions manually is a nightmare.

The Solution
nvm allows you to define and switch the active Node.js version per terminal session or per project directory. It ensures you always run the correct version for the task at hand.

When updating a dependency or preparing for a Node.js major release, you need to verify compatibility.

The Benefit
You can quickly install and switch to different Node.js versions (e.g., jump from Node 18 to Node 20) to run your test suite against them. This dramatically speeds up testing and migration efforts.

nvm manages Node.js and its associated npm (Node Package Manager) and global packages independently for each installed version.

The Outcome
Global packages (like TypeScript or utility CLIs) installed under Node 14 won't clutter or conflict with packages installed under Node 20. This keeps your environment clean and avoids version conflicts.

Since nvm is a POSIX-compliant shell script, installation is straightforward, typically involving a single command.

You can install nvm using either curl or wget. It's generally recommended to check the official nvm-sh/nvm GitHub repository for the absolute latest installation command, but here is the common approach

# 1. Use curl to download and run the install script. 
#    Replace '0.39.7' with the latest version number if necessary.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

What this does

It downloads the install.sh script.

It creates the ~/.nvm directory.

It attempts to add the necessary loading code to your shell's profile file (e.g., ~/.bashrc, ~/.zshrc, or ~/.profile).

After running the script, you'll need to close and reopen your terminal, or manually source your profile file (source ~/.bashrc) for nvm to become available.

Once installed, here are the most crucial commands you'll use daily

CommandDescriptionExample
nvm install <version>Installs a specific Node.js version. Use lts/* for the latest Long-Term Support version.nvm install 20.10.0
nvm use <version>Switches your current shell session to use the specified Node.js version.nvm use 18
nvm listLists all installed versions and indicates which one is currently active.nvm list
nvm alias default <version>Sets a default Node.js version to use in any new shell.nvm alias default 20
nvm uninstall <version>Removes a specific installed version.nvm uninstall 14.21.3
nvm currentShows the currently active Node.js version.nvm current

Imagine you have two projects
Project Alpha (legacy) and Project Beta (new).

ProjectRequired Node Version
AlphaNode 16
BetaNode 20

First, make sure both versions are installed on your system

# Install Node 16 (LTS Gallium)
nvm install 16 

# Install Node 20 (LTS Iron)
nvm install 20 

# Check the list to confirm installation
nvm list 

Output of nvm list might look something like this

->     v20.10.0  # Currently active
       v16.20.2
default -> 20 (-> v20.10.0)

Navigate to the project directory and switch the version

cd ~/projects/alpha

# Switch to Node 16 for this session
nvm use 16 

# Run your project (it will now use Node 16's binary)
npm start 

Open a new terminal window (or simply switch versions) to work on Project Beta

cd ~/projects/beta

# Switch to Node 20 for this session
nvm use 20 

# Run your project (it will now use Node 20's binary)
npm run dev 

Pro Tip
Automating the Switch

To avoid manually typing nvm use <version>, you can create a file named .nvmrc in your project's root directory containing only the version number (e.g., 16.20.2 or simply 16).

Then, when you navigate to the directory, you can simply run

# In the project directory with a .nvmrc file
nvm use 
# nvm automatically detects the version from .nvmrc and switches!

nvm-sh/nvm




Bun vs. The World: Why This All-in-One JavaScript Runtime is a Game-Changer

Bun is an incredibly exciting, modern JavaScript runtime that aims to be an all-in-one toolkit for your JavaScript and TypeScript development


XPipe: Streamlining Your Infrastructure from Bash to Docker

Let's dive into XPipe, a tool that essentially acts as a unified connection hub for your entire infrastructure.At its core


freeCodeCamp for Engineers: Skills, Contributions, and Code

First off, let's talk about freeCodeCamp. It's a massive open-source project that provides a free, comprehensive curriculum for learning web development and computer science


Serverless DNS: The Edge Resolver for Modern Software Engineers

As a software engineer, this project offers some really powerful advantages and a flexible deployment model.This project is essentially a self-hosted


From Minutes to Hours: Mastering Multi-Agent Orchestration with Deer-Flow

Let’s dive into Deer-Flow by ByteDance. Think of it not just as another chatbot, but as a highly capable digital coworker that can handle the "heavy lifting" of research and coding


Deep Dive: Orchestrating Scalable Node.js Applications with Synkra AIOS Core

Since this is the Core Framework v4. 0, it's designed to handle the heavy lifting of AI orchestration so you can focus on building features rather than wrestling with LLM prompts and state management


A Deep Dive into Secure Software Development with Bitwarden's Client Codebase

The bitwarden/clients repository is a goldmine for any software engineer interested in building secure, cross-platform applications


Social-Analyzer: A Software Engineer's Guide to OSINT Integration

This is a powerful OSINT (Open-Source Intelligence) tool designed to automatically find and analyze a person's profile across a vast network of over 1000 social media platforms and websites using a given username


Mastering Node.js: A Guide to Best Practices for Software Engineers

Let's dive into a fantastic resource that can significantly level up your Node. js game goldbergyoni/nodebestpractices. Think of it as a meticulously curated handbook for writing top-notch Node


Powering Your WebGL Apps: An Engineer's Look at the PlayCanvas Editor

The PlayCanvas Editor is a powerful, browser-based visual editor that streamlines the development of interactive 3D applications