How to Install NVM on Ubuntu (2026 Guide) – Manage Multiple Node.js Versions Like a DevOps Engineer
Introduction
If you work with Node.js applications, React projects, Next.js apps, APIs, or DevOps environments, one common problem you will face is Node.js version conflicts.
One project may require Node.js 18, another may require Node.js 20, and sometimes production servers still run older LTS versions. Installing everything globally can quickly turn into a mess.
This is where NVM (Node Version Manager) becomes a lifesaver.
In this complete guide, you will learn how to install NVM on Ubuntu, manage multiple Node.js versions safely, switch versions without breaking your system, and follow real DevOps best practices used in production environments.
- Introduction
- Real DevOps Story: Production Broke After Node Upgrade
- What is NVM and Why You Should Use It?
- Step 1: Update Ubuntu System
- Step 2: Install NVM on Ubuntu
- Step 3: Verify NVM Installation
- Step 4: Install Node.js Using NVM
- Step 5: Switch Between Node Versions
- Important NVM Commands Explained
- Use Project-Specific Node.js Version
- Best Practices for Production (DevOps Tips)
- Common Errors and Fixes
- Internal Resources (Recommended Guides)
- Frequently Asked Questions (FAQ)
- Conclusion
Real DevOps Story: Production Broke After Node Upgrade
In one production environment, a developer upgraded Node.js directly using Ubuntu packages because a React build required a newer version.
The issue?
Another backend service running on the same server depended on an older Node.js version. After the upgrade, the service failed to start and production APIs stopped working.
The team spent hours troubleshooting before realizing the issue came from a Node version mismatch.
This is exactly why DevOps engineers prefer NVM in staging and development environments.
What is NVM and Why You Should Use It?
NVM (Node Version Manager) is a tool used to install, manage, and switch between multiple Node.js versions on the same machine.
Instead of replacing your existing Node.js installation, NVM keeps versions isolated and lets you switch instantly.
- Multiple Node Versions: Install Node 16, 18, 20, 22 simultaneously
- Safe Upgrades: No risk of breaking existing applications
- Project Isolation: Different projects can use different versions
- DevOps Friendly: Great for CI/CD and deployment environments
- Easy Switching: Change versions with one command
Step 1: Update Ubuntu System
Before installing NVM, always update your Ubuntu packages.
sudo apt update && sudo apt upgrade -y
This helps avoid dependency and compatibility issues.
Step 2: Install NVM on Ubuntu
Install NVM using the official installation script.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
The installation script downloads and configures NVM automatically inside your user account.
Why this method?
Because Ubuntu repositories usually contain older versions, while the official NVM installation gives you the latest stable version.
Reload Bash Profile
After installation, reload your terminal profile.
source ~/.bashrc
If you are using Zsh shell:
source ~/.zshrc
Step 3: Verify NVM Installation
Check whether NVM installed correctly:
nvm --version
If installation succeeds, you will see the installed version number.
Example output:
0.40.3
If you see command not found, reload your shell using:
source ~/.bashrc
Step 4: Install Node.js Using NVM
One of the biggest advantages of NVM is installing multiple Node.js versions easily.
Install Latest Node.js Version
nvm install node
This installs the latest stable version.
Install Specific Node.js Version
nvm install 20
Or install an exact version:
nvm install 20.19.2
This is highly recommended for production stability.
Install LTS Version
nvm install --lts
LTS (Long-Term Support) versions are recommended for production environments because they receive long-term security updates.
Step 5: Switch Between Node Versions
You can easily switch between installed versions.
Check Installed Versions
nvm list
Example output:
-> v20.19.2
v18.20.8
default -> 20
node -> stable
Switch to Another Version
nvm use 18
This immediately switches the active Node.js version.
Check Current Node Version
node -v
Important NVM Commands Explained
| Command | Purpose | Explanation |
|---|---|---|
nvm install node |
Install latest version | Installs newest stable Node.js |
nvm install --lts |
Install LTS version | Recommended for production |
nvm install 20 |
Install specific version | Install required project version |
nvm list |
Show versions | Displays installed Node versions |
nvm use 20 |
Switch version | Changes active Node version |
nvm current |
Current version | Shows active Node version |
nvm uninstall 18 |
Remove version | Deletes unused Node version |
nvm alias default 20 |
Set default version | Automatically loads Node 20 |
Use Project-Specific Node.js Version
Inside your project folder, create a Node version file.
echo "20" > .nvmrc
Then run:
nvm use
NVM automatically detects the required Node version from the .nvmrc file.
This is extremely useful for teams because everyone uses the same Node version.
Best Practices for Production (DevOps Tips)
- Always use
LTSversions for production servers - Never upgrade Node.js directly on production without testing
- Document Node versions in deployment scripts
- Use
.nvmrcfor project consistency - Avoid installing global npm packages unnecessarily
- Test builds after switching Node versions
- Pin exact Node versions in CI/CD pipelines
Common Errors and Fixes
| Error | Cause | Solution |
|---|---|---|
| NVM command not found | Shell not reloaded | Run source ~/.bashrc |
| Permission denied | Using sudo with NVM | Never use sudo for NVM |
| Wrong Node version | Default not set | Use nvm alias default 20 |
| Build failed | Old Node version | Switch to supported Node version |
Internal Resources (Recommended Guides)
To improve your DevOps workflow, read these guides:
Frequently Asked Questions (FAQ)
1. Is NVM safe for Ubuntu?
Yes. NVM installs Node.js inside your user directory and does not affect system packages.
2. Can I install multiple Node.js versions?
Yes. You can install unlimited Node versions and switch anytime.
3. Which Node version is best for production?
LTS versions are always recommended for production workloads.
4. Why should I use NVM instead of apt install nodejs?
Ubuntu repositories may contain older versions, and switching between versions becomes difficult.
5. Can I use NVM in production servers?
Yes, especially in staging and deployment environments where multiple projects require different versions.
6. How do I uninstall NVM?
rm -rf ~/.nvm
Then remove NVM configuration lines from .bashrc.
Conclusion
You now understand how to install NVM on Ubuntu and manage multiple Node.js versions like a professional DevOps engineer.
Using NVM helps avoid version conflicts, improves deployment stability, and keeps your development workflow clean and professional.
If you work with React, Next.js, Node.js APIs, or DevOps automation, learning NVM is one of the most valuable skills you can have.