How to Install Node.js on Ubuntu 26.04 and 24.04

Share

To install Node.js on Ubuntu 26.04 or 24.04, use nvm (Node Version Manager) for a current LTS release and easy version switching, or APT for Ubuntu-managed packages. nvm installs and switches Node.js versions for your user without replacing Ubuntu’s system-managed installation. Node.js runs JavaScript outside a browser; npm installs project packages.

This guide covers installation, a practical test, updates and removal. If you need help, leave a comment or contact us.

Before you begin
  • Ubuntu 26.04 LTS or 24.04 LTS, internet access and a sudo account.
  • Choose one method first. Existing applications may depend on an installed system version.
  • For nvm, use a regular user account and a Bash or Zsh shell. Node installed this way belongs to that user.

Choose an Installation Method

Check the version your project requires before choosing. As of November 2026, Node.js 26 is the latest Active LTS release; Node.js 24 remains supported. LTS releases receive longer maintenance than short-lived releases.

Method Best for Updates
nvm Current LTS and switching project versions for one user Install a newer release with nvm
Ubuntu APT Distribution packages available system-wide Ubuntu package updates through APT

Ubuntu 26.04 ships the Node.js 22 series; 24.04 ships 18. Node.js 18 is past upstream end of life, so use a supported LTS release for new development. Ubuntu package support and upstream support are separate; check Ubuntu security status for your release and subscription. The available APT candidate can change with configured repositories.

Check for an Existing Installation

1Inspect your shell and packages

These checks show which commands your current shell finds and whether APT owns a Node.js package. Missing commands or no installed package are normal on a fresh system.

Terminal
command -v node
command -v npm
node --version
npm --version
dpkg-query -W nodejs npm 2>/dev/null
apt-cache policy nodejs npm

Paths under your home directory can indicate a user-managed installation; /usr/bin usually indicates a system package. Do not remove a working runtime until you know what depends on it.

Install Node.js with nvm

1Install prerequisites

Refresh package lists, then install download tools and the library required by recent official Linux binaries:

Terminal
sudo apt update
sudo apt install curl ca-certificates libatomic1

Stop if APT reports an error. nvm supports multiple shell environments; the commands below assume Bash.

2Download and review the nvm installer

Download the official release script, inspect it, and run it as your normal user. The installer modifies your shell profile and normally installs into ~/.nvm; an existing NVM_DIR or XDG configuration can change the location.

Terminal
nvm_installer=$(mktemp) && curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh -o "$nvm_installer" && less "$nvm_installer"

Press q to exit the viewer. In the same terminal, only run the script after a successful download and review:

Terminal
bash "$nvm_installer"

After the installer finishes successfully, remove the downloaded temporary file in the same terminal, while its path is still stored in the shell variable:

Terminal
rm -- "$nvm_installer"

Then open a new terminal so the profile changes load. Do not use sudo to install or run nvm.

3Install and select an LTS release

In the new terminal, confirm nvm is loaded, then install the latest LTS release:

Terminal
command -v nvm
nvm install --lts
nvm current
node --version
npm --version
command -v node
command -v npm

The first command should print nvm. Node and npm paths should point inside your nvm directory. If nvm is not found, see Troubleshooting. The latest LTS major changes over time; use a project-specific version when required.

4Use a project version

If a project contains an .nvmrc file, run these commands from its directory to install and select the specified version:

Terminal
nvm install
nvm use
node --version

Changing directories alone does not automatically select the version. To install a specific supported major, for example 24 rather than the latest LTS, use nvm install 24 and nvm use 24. Check the project requirements and Node.js release schedule first.

For servers, nvm installs Node.js for the current user. systemd services do not automatically load that user’s interactive nvm environment, so a service may need an explicit Node.js executable path or another suitable installation strategy.

Install Node.js with Ubuntu APT

1Check the candidate

Use this alternative if you need Ubuntu-managed system packages. Node.js and npm are separate packages in Ubuntu. The Universe repository must be enabled. Check the candidate and its source:

Terminal
sudo apt update
apt-cache policy nodejs npm

If no candidate appears, enable Universe in Software & Updates, refresh the package index and check again. If a third-party source is selected, resolve that before continuing; this section assumes Ubuntu packages.

2Preview and install

Review the proposed transaction, especially removals on a system with an existing installation. Stop if it would remove software you need.

Terminal
sudo apt install --simulate nodejs npm

If the proposal is acceptable, install and verify:

Terminal
sudo apt install nodejs npm
node --version
npm --version
command -v node
command -v npm

When nvm is active, the shell may still find its user-managed Node.js first. Use nvm use system to check the system version in that shell.

Test Node.js and npm

Run a small JavaScript expression, then ask npm for its configured registry. This does not create or alter a project:

Terminal
node -e "console.log('Hello from Node.js')"
npm config get registry

The first command should print Hello from Node.js. The second normally prints the npm registry URL; a different URL can be intentional for an organization. This confirms npm runs, not that network access to the registry works.

Optionally, check connectivity to the configured registry:

Terminal
npm ping

A successful response means npm reached the configured registry. A failure can be caused by network, proxy, registry or authentication settings; it does not necessarily mean npm is installed incorrectly. For editing projects, see Visual Studio Code for Ubuntu. To put Node.js to use, create a React project on Ubuntu.

Update Node.js Safely

For nvm, check your project compatibility before installing another major. To update within a chosen major, install it again and select it. Here, 24 is an example of a supported major, not necessarily the latest LTS; replace it with the major your project supports:

Terminal
nvm install 24
nvm use 24
nvm current

nvm installs a separate version. Global npm tools belong to their installed Node version and may need reinstalling. To use that major in new shells, run nvm alias default 24. Update nvm itself separately using its official instructions.

For Ubuntu packages, refresh APT and preview upgrades before applying them. This updates the installed Ubuntu packages, not an nvm installation:

Terminal
sudo apt update
sudo apt install --only-upgrade --simulate nodejs npm

Review the preview before applying it:

Terminal
sudo apt install --only-upgrade nodejs npm

Ubuntu may backport fixes without changing the upstream major. Do not assume a major upgrade is safe for an existing application.

Troubleshooting

1nvm: command not found

Open a new Bash terminal after installation. Check your installer output and shell startup file. For the usual default location, load nvm for this session:

Terminal
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
command -v nvm

If you use a custom NVM_DIR or XDG location, use that location instead. Check the nvm Linux troubleshooting notes if it still does not load.

2Wrong Node.js version or npm permission error

Run command -v node, command -v npm and nvm current if nvm is loaded. Select the project version with nvm use, or nvm use system for APT. Avoid using sudo with nvm or changing ownership of system directories. A custom npm prefix can conflict with nvm; inspect npm config get prefix and your user npm configuration before changing it.

3Missing libatomic or native build tools

If Node reports a missing libatomic.so.1, install libatomic1 with APT and retry. Some npm dependencies compile native code; if an error mentions a compiler or node-gyp, install build-essential and python3, then check that the dependency supports your Node and Python versions. Do not replace Ubuntu system Python.

Remove Node.js

Back up project files and identify applications that rely on the runtime first. Removal of a runtime can stop those applications.

1Remove an nvm-managed version

List installed versions and switch away from the version to remove:

Terminal
nvm ls
nvm deactivate

Then run nvm uninstall VERSION, replacing VERSION with the exact unwanted version shown by nvm ls. Global npm packages installed under that version are removed with it. To remove nvm itself, first inspect your configured NVM_DIR and shell profile, back up anything needed, and follow the manual uninstall instructions.

2Remove Ubuntu packages

If you used Ubuntu APT packages, preview dependent removals first:

Terminal
sudo apt remove --simulate nodejs npm

Proceed only if the proposed changes are acceptable:

Terminal
sudo apt remove nodejs npm
sudo apt autoremove --dry-run

Run sudo apt autoremove only after reviewing the dry run. These commands do not remove your project files or an nvm installation.

Frequently Asked Questions

Does Node.js include npm?

Node.js installed through nvm includes npm. Ubuntu provides npm as a separate package.

Can I have more than one Node.js version?

Yes. nvm keeps versions under your user account and lets you select one in each shell.

Why does Ubuntu install an older Node.js version?

Ubuntu maintains distribution packages for each release. Their major versions may differ from the latest upstream LTS release.

Does updating with APT update nvm versions?

No. APT updates system packages. Use nvm to install and select updates for an nvm-managed runtime.

Will removing Node.js delete my projects?

The commands above remove the selected runtime or packages, not your project directories. Back up important files before making changes.

Related guides: Install Docker on Ubuntu and install a LEMP stack.