If you work with Node.js applications, you often need to switch between multiple Node versions for different projects. Installing Node.js globally can quickly become messy and restrictive.
That’s where NVM (Node Version Manager) comes in.
NVM allows you to:
- Install multiple Node.js versions on the same system
- Switch Node versions per project or per shell
- Avoid conflicts between Node.js versions
- Easily upgrade or downgrade Node.js when required
In this tutorial, you’ll learn how to install NVM on Ubuntu, install Node.js using NVM, and switch between Node versions efficiently.
What is NVM?
NVM (Node Version Manager) is a command-line tool that lets you install and manage multiple Node.js versions on a single machine. Each user gets their own isolated Node environment without affecting the system-wide setup.
This is especially useful when:
- You are working on legacy Node.js projects
- You manage multiple applications with different Node requirements
- You deploy apps on the same VM with different Node versions
Prerequisites
Before installing NVM, ensure:
- You are using Ubuntu
- You have a non-root user with
sudoprivileges - You have internet access
Step 1: Update Ubuntu Packages
Always start by updating your package list to ensure you install the latest available dependencies.
sudo apt-get update
This command refreshes your local package index and helps avoid installation issues.
Step 2: Install Curl
NVM installation requires curl to download the installer script.
sudo apt install curl
Verify curl installation:
curl --version
Step 3: Install NVM on Ubuntu
Use the official NVM installation script from GitHub:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
This command:
- Downloads the NVM installer
- Adds NVM configuration to your shell profile (
~/.bashrcor~/.zshrc) - Sets up environment variables
Apply Changes
After installation, either:
- Open a new terminal
OR - Reload your shell profile:
source ~/.bashrc
Step 4: Verify NVM Installation
Confirm that NVM is installed correctly:
nvm --version
If you see a version number, NVM is successfully installed.
Step 5: List Installed Node.js Versions
Check which Node versions are currently installed:
nvm ls
Initially, this list will likely be empty because Node is not installed yet.
Step 6: Install Node.js Using NVM
Install Node.js version 24 (you can install any version you need):
nvm install 24
NVM will:
- Download Node.js
- Set it up under your user environment
- Automatically select it as the default version (if none existed)
Step 7: Use a Specific Node.js Version
Switch to Node.js version 24:
nvm use 24
Verify the active Node version:
node -v
Why Use NVM Instead of System Node.js?
| Feature | NVM | System Node |
|---|---|---|
| Multiple Node versions | ✅ Yes | ❌ No |
| Easy version switching | ✅ Yes | ❌ No |
| User-level installation | ✅ Yes | ❌ No |
| Safe upgrades | ✅ Yes | ❌ Risky |
Common NVM Commands (Bonus)
nvm install node # Install latest Node.js
nvm install --lts # Install latest LTS version
nvm use --lts # Use LTS version
nvm uninstall 16 # Remove a Node version
Conclusion
NVM is an essential tool for any Node.js developer or DevOps engineer working on Ubuntu. It provides flexibility, avoids version conflicts, and simplifies Node.js management across multiple projects.
By following this guide, you can:
- Install NVM safely on Ubuntu
- Manage multiple Node.js versions
- Switch Node versions effortlessly on the same VM
If you frequently work with Node.js applications, NVM is a must-have tool for your development and production environments.