Managing Multiple Node.js Versions with NVM on Ubuntu 24.04: A Developer’s Guide

Using NVM on Ubuntu 24.04 allows developers to manage multiple Node.js versions easily, preventing conflicts across projects. The guide covers installation steps, including system updates, necessary tools, and NVM setup, along with commands for installing and switching Node.js versions. It also provides tips for workflow efficiency and troubleshooting common issues related to NVM usage.
Sakib Rahman
Sep 26, 2025
4 min read
118 views

In the world of Node.js development, it’s common to juggle multiple versions of Node across different projects. Using a single global Node installation can lead to version conflicts, dependency issues, or surprises in production. That’s where NVM (Node Version Manager) shines: it enables you to install, switch, and manage multiple Node.js versions side by side on the same machine.

https___dev-to-uploads.s3.amazonaws.com_uploads_articles_tns0q1sn1n531uk9e8mt.webp

In this guide, I’ll walk you through installing NVM on Ubuntu 24.04, show you how to use it effectively, and offer best practices to keep your setup stable. Let’s get started.

Why Use NVM?

1. Switch Node.js versions seamlessly: Perfect for projects that require specific Node versions.

2. Isolated environments: Run multiple Node.js versions without interference between them.

3. User-friendly workflow: Install, remove, and manage Node.js versions with simple command-line operations.

Step 1: Update Your System

It’s crucial to update your system first, to ensure dependencies and package sources are current:

bash
sudo apt update
sudo apt upgrade -y

Also, consider rebooting if you haven’t done that in a while, especially if kernel or low-level packages were upgraded.

Step 2: Install Necessary Tools

You’ll need tools to download files and compile modules when required:

bash
sudo apt install -y curl build-essential libssl-dev
  • curl → For fetching remote scripts.
  • build-essential → For compiling C/C++ add-ons (npm modules that need binaries).
  • libssl-dev → Some Node versions/modules need SSL libraries.

Step 3: Download & Install NVM

Here we fetch the official installer and run it:

bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/vX.Y.Z/install.sh | bash
  • Replace vX.Y.Z with the latest stable NVM version.
  • This script creates a .nvm directory in your home (~/.nvm), and updates your shell config (like ~/.bashrc or ~/.zshrc) to load NVM automatically.

Step 4: Activating NVM in Your Shell

After installation, you need to enable it:

bash
# Either in current session:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

# Then, add these lines into ~/.bashrc or ~/.zshrc so they are loaded on login.

To apply changes right away:

bash
source ~/.bashrc    # or source ~/.zshrc

Step 5: Confirming Installation

Check NVM is available:

bash
nvm --version

If this returns something like 0.40.x (or whatever current), you’re good.

Step 6: Using NVM to Handle Node.js Versions

With NVM ready, you’ll want to do things like:

Install the latest stable version

bash
nvm install node

Install the current LTS version

bash
nvm install --lts

Install a specific version

bash
nvm install 18.17.0

Switch to a version for current session

bash
nvm use 18.17.0

Set a default version, so new shells use it automatically

bash
nvm alias default 18.17.0

List versions you have installed

bash
nvm ls

See all Node.js versions available to install remotely

bash
nvm ls-remote

Step 7: Workflow Tips & Tricks

These are the little practices that make your life easier:

  • Use a `.nvmrc` file: In a project folder, put a file named .nvmrc with a version (e.g. 18.17.0). Then you and your team can use nvm use inside that project to automatically pick the right version.
  • Global packages per version: If you install global npm packages under one Node version, they won’t automatically be available under another. Use -reinstall-packages-from=<old_version> when installing a new version to copy over global packages.
  • Avoid mixing apt-installed Node with NVM: If you had Node.js from Ubuntu’s package manager before, consider removing it (sudo apt remove nodejs) to avoid conflicts.

Step 8: Common Issues & Fixes

Here are issues you might encounter, plus how to fix them:

ProblemSymptomsFix
nvm: command not found after installThe shell doesn’t load NVM automaticallyEnsure lines added to .bash / .zshrc by installer are present; then source the file or open a new terminal.
Old Node still used by systemnode -v returns old version even after nvm useRemove or disable the system Node; ensure your PATH is set so NVM’s bin comes first.
Permission errors when installing npm packagesErrors related to permissions when installing global packagesDon’t use sudo with npm when using NVM; global installs happen in user’s home directory.

Conclusion

Setting up NVM on Ubuntu 24.04 gives you control, flexibility, and peace of mind when working with Node.js. Once it’s in place, switching versions becomes second nature, which is especially helpful when maintaining multiple projects, testing compatibility, or just staying up to date with Node.js.

NVM
Nodejs
Ubuntu