Managing Multiple Node.js Versions on Linux Using NVM
This deep-dive covers manage node versions nvm with actionable analysis, practical implications, and expert insights.
Why Avoid System Node Packages?
Installing Node.js via sudo apt install nodejs locks you into an outdated distribution version and forces you to run global npm commands as root. Node Version Manager (NVM) installs Node runtimes entirely within your user home directory, enabling smooth version switching without permission errors.
Step 1: Installing NVM on Ubuntu
Run the official NVM install script from GitHub:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
Source your shell configuration or open a new terminal window:
source ~/.bashrc
# Or if using zsh: source ~/.zshrc
Step 2: Installing Specific Node.js Versions
Install the latest Long-Term Support (LTS) release alongside the latest current release:
# Install current LTS (e.g. Node 20.x)
nvm install --lts
# Install latest release (e.g. Node 22.x)
nvm install 22
# Verify installed versions
nvm ls
Step 3: Switching Active Versions
Switch between versions on the fly:
nvm use 20
node -v
nvm use 22
node -v
Step 4: Using .nvmrc for Team Consistency
To ensure all team members use the identical Node version, create an .nvmrc file in your repository root:
echo "20" > .nvmrc
nvm use
Global npm packages installed with NVM are isolated per Node version and never require root permissions.
Was this technical analysis helpful?
Your feedback informs our benchmark updates and ongoing article audits.
FAQ
Frequently Asked Questions
Structured for search engines and AI answer systems (AEO/GEO).
System packages often ship older versions and place global packages into /usr/lib/node_modules, requiring sudo to install npm packages globally.
Place an .nvmrc file in your project root containing the version number (e.g. 20), then run nvm use in that folder.
Run nvm alias default 20 to set Node 20 as your persistent default.
More answers in our FAQ hub.
Newsletter
Practical Linux & Applied AI Newsletter
Get new tested tutorials and benchmark comparisons delivered directly to your inbox. Zero spam.
Join Weekly guides readers getting our weekly digest.
- Practical Linux administration & terminal workflows
- Tested open-source AI setups & benchmarks
- Zero spam - unsubscribe anytime