How to Install Node on Ubuntu: 4 Methods to Get a Specific Version
The best way to install Node on Ubuntu with a specific version is to bypass the default apt repositories and use either the NodeSource APT repository for system-wide binary installs or NVM for per-user version management.
When you need to install Node on Ubuntu with a precise version rather than the outdated default in Ubuntu's repositories, you must use alternative distribution channels. The official nodejs/node repository provides the source code and build instructions documented in BUILDING.md, but most users should install the pre-built binaries distributed through official channels. This guide covers four reliable methods to install Node on Ubuntu while controlling exactly which version runs on your system.
Why Avoid the Default Ubuntu Node.js Package
Ubuntu’s package manager (apt) only provides the version of Node.js shipped with the specific Ubuntu release. For example, Ubuntu 20.04 typically ships with Node.js v12, which may lack critical security patches or features required by modern applications. The binaries in the official Ubuntu repositories also lag behind the security updates published in the doc/changelogs/CHANGELOG_V*.md files within the nodejs/node repository.
Method 1: Install Node on Ubuntu Using NodeSource APT Repository
The NodeSource APT repository provides pre-built Debian packages for every Node.js major version. These binaries are compiled on RHEL 8 with glibc ≥ 2.28, matching the official Node.js Linux binary specifications documented in BUILDING.md.
Step 1: Add the NodeSource Repository
Replace 18.x with your desired major version (e.g., 16.x, 20.x, 22.x):
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
Step 2: Install Node.js
sudo apt-get install -y nodejs
Step 3: Verify the Installation
node --version
The output should reflect the specific major version you requested (e.g., v18.20.2), not the default Ubuntu package version.
Method 2: Install Node on Ubuntu Using NVM
Node Version Manager (nvm) is a shell script that downloads official tarballs from nodejs.org/dist and manages multiple Node.js versions side-by-side. This method is ideal when you need to switch between versions for different projects or test against specific releases documented in doc/changelogs/.
Step 1: Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Step 2: Load NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Step 3: Install a Specific Version
Install an exact version, major version, or LTS alias:
nvm install 16.20.2
nvm install 18
nvm install --lts
Step 4: Use the Installed Version
nvm use 16.20.2
node --version # → v16.20.2
Method 3: Install Node on Ubuntu Using asdf
If you already use asdf for managing multiple language runtimes, the asdf-nodejs plugin provides the same granularity as nvm but within the asdf ecosystem.
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git
asdf install nodejs 18.20.2
asdf global nodejs 18.20.2
node --version # → v18.20.2
Method 4: Manual Tarball Installation
For CI pipelines, container builds, or one-off installations, manually downloading the official tarball gives you complete control without any version-manager indirection. This method uses the same release tarballs referenced in the "Downloading binaries" section of BUILDING.md.
# Define the exact version and architecture
VERSION=v20.10.0
ARCH=linux-x64
# Download from the official distribution site
curl -O https://nodejs.org/dist/${VERSION}/node-${VERSION}-${ARCH}.tar.xz
# Extract and install to /usr/local
tar -xf node-${VERSION}-${ARCH}.tar.xz
sudo mv node-${VERSION}-${ARCH} /usr/local/node-${VERSION}
# Add to system PATH
echo 'export PATH=/usr/local/node-${VERSION}/bin:$PATH' | sudo tee /etc/profile.d/node.sh
source /etc/profile.d/node.sh
# Verify installation
node --version # → v20.10.0
Key Files in the Node.js Repository
Understanding these files in the nodejs/node repository helps verify why these installation methods work:
| File | Relevance to Version-Specific Installation |
|---|---|
BUILDING.md |
Documents supported platforms and the "Downloading binaries" section that explains where official tarballs are hosted (the same source used by nvm and manual installs). |
doc/changelogs/CHANGELOG_V*.md |
Contains release notes for each major version, helping you decide which specific version to pin based on security fixes and ABI changes. |
tools/install.py |
The internal installation script used when building from source; understanding it clarifies why binary installs are preferred for specific version control. |
doc/node.1 |
The man page confirming that node --version reports the binary version, useful for verifying installations. |
Summary
- NodeSource APT repository is the best method to install Node on Ubuntu when you want system-wide installation with
aptintegration and automatic security updates. - NVM is ideal when you need multiple Node.js versions side-by-side or want to switch versions without root privileges.
- asdf works best if you already use asdf to manage other language runtimes and want a unified version manager.
- Manual tarball installation provides the most control for CI/CD pipelines or containerized environments where you want to avoid package manager overhead.
All four methods pull binaries from the official nodejs.org distribution infrastructure documented in the BUILDING.md file, ensuring you get the exact version specified rather than the outdated default in Ubuntu's repositories.
Frequently Asked Questions
Can I install a specific Node.js version using apt-get?
No, Ubuntu's official repositories only provide the Node.js version shipped with that Ubuntu release. To install a specific version using apt, you must add a third-party repository like NodeSource, which provides version-specific packages (e.g., setup_18.x for Node.js 18).
How do I switch between multiple Node.js versions on Ubuntu?
Use NVM (Node Version Manager). After installing NVM, you can install multiple versions with nvm install 16.20.2 and nvm install 18.20.2, then switch between them instantly using nvm use 16.20.2 or nvm use 18.20.2 without needing sudo access.
Is it safe to use NodeSource repositories for production servers?
Yes, NodeSource repositories are widely trusted in the industry and provide binaries compiled with the same toolchain specifications documented in the official BUILDING.md file. They receive security updates shortly after upstream Node.js releases, and using apt upgrade will automatically apply patches for your specific major version.
How do I verify which Node.js version is installed?
Run the command node --version in your terminal. This outputs the version string (e.g., v18.20.2) of the node binary currently in your PATH. This behavior is documented in the doc/node.1 man page within the Node.js source repository.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →