How to Install Node.js and npm on Ubuntu

Ubuntu’s package listing shows Node.js 18.19.1, while the project’s setup notes call for a supported release. I was surprised that the distribution’s version number could matter before the first line of app code runs.

The practical goal is a runtime that matches the project’s support range, with npm ready for its packages. It helps to start by separating what Node.js runs from what npm installs.

Node.js and npm are installed together

Node.js runs JavaScript outside a browser, while npm installs packages for Node.js projects and ships with the nvm-managed Node.js runtime.

Install sourceWhat it managesChoose it when
nvmNode.js versions in your user account, with npm for each versionYou develop projects and need to switch Node.js releases without changing the system runtime
Ubuntu APTNode.js and npm as Ubuntu system packagesYou want packages managed with the rest of the distribution and accept its release line
NodeSource APTA system-wide Node.js package from NodeSourceA host service needs Node.js outside a developer’s shell

npm’s installation guide recommends a Node version manager, and the Node.js release page labels v24.21.0 as LTS, so nvm is the better default for a development account. Ubuntu Noble’s archive lists Node.js 18.19.1 and npm 9.2.0, so check those suite versions if your project needs an upstream-supported Node.js release.

What you need before installing

Run nvm’s installer from Bash with a download tool and internet access, then reload its startup lines from the profile using a regular Ubuntu account.

  • Open a terminal as the account that will run Node.js. nvm installs versions under that user’s home directory, so do not run its installer with sudo.
  • Close any package-manager choice first. If the system already has Node.js from APT, nvm can coexist with it, but your shell’s PATH decides which node and npm commands run.

Install Node.js and npm with nvm

nvm keeps Node.js and npm under your account, separate from Ubuntu’s system packages. Install it, load its Bash function, and select the LTS release.

Step 1: Install nvm

Run the official nvm installer, then reload Bash’s startup file in the same terminal. New Bash sessions will read the nvm lines the installer adds.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
source ~/.bashrc

nvm stays under your user account and does not need sudo, and its installer is published in the official nvm project.

Step 2: Install the LTS release

Node.js recommends an Active or Maintenance LTS release for production, so use nvm’s LTS channel. The command follows that channel instead of pinning one Node.js version.

nvm install --lts

Set a default alias when new Bash sessions should start on an LTS release.

Step 3: Make LTS the default

Set the default alias only if you want a fresh terminal to choose an LTS version. This leaves any Ubuntu-managed Node.js package untouched.

nvm alias default 'lts/*'

The alias resolves to an installed LTS version, so new Bash sessions start there without replacing Ubuntu’s Node.js package.

Verify both commands

Reload Bash and check Node.js and npm from the same shell. The first command should print a v-prefixed Node.js release, and the second should print npm’s version.

source ~/.bashrc && node -v && npm -v

The screenshot shows Node.js v24.21.0 and npm 11.19.0 together, confirming that npm is available in the shell that will run your project.

Terminal output showing Node.js v24.21.0 and npm 11.19.0
The nvm-managed Node.js LTS install includes npm, and both version commands return a version.

Fix a missing npm or nvm command

If Bash says nvm or npm cannot be found, the active shell may not have loaded nvm, or another installation may be earlier in PATH. Reload the profile first, then inspect which executable your shell will run.

source ~/.bashrc
nvm use --lts
type -a node npm
What you seeWhat to do
nvm: command not foundOpen a new Bash terminal or source ~/.bashrc, then check that the installer added nvm’s startup lines.
npm: command not foundRun nvm use –lts in the shell where nvm is loaded. nvm installs npm alongside that Node.js version.
node -v shows an unexpected releaseUse type -a node npm to find duplicate paths. Run nvm use –lts to put the selected LTS version first for this shell.
A package fails while compiling a native addonThat package needs a compiler toolchain, not a second npm installation. Follow the package’s Ubuntu build prerequisites before retrying.

Ubuntu’s APT packages and nvm-managed versions can coexist, but avoid mixing their global package directories. If an npm command asks for sudo or reports a permissions error, check that the shell is using the nvm path before changing system ownership.

Keep one owner for Node versions

Use nvm for the Node.js versions that belong to your development account, and leave Ubuntu’s packages to system-managed software. Since npm follows the selected Node.js version, one version manager is enough to keep both commands aligned.

nvm ls

Run that command when you need to see which Node.js releases this account can select.

Node.js and npm on Ubuntu questions

nvm installs npm with Node.js, while Ubuntu APT manages both through the distribution’s package archive.

Does installing Node.js with nvm also install npm?

Yes. nvm installs Node.js with its bundled npm, so you do not need a separate npm install for this setup.

Should I install Node.js with APT or nvm on Ubuntu?

Use nvm for a developer account that needs to select or switch Node.js releases. Use Ubuntu APT when you want the distribution to manage the system package and its release line.

Why does Bash say npm is not found after installation?

The shell may not have loaded nvm or selected its Node.js version. Open a new Bash terminal, source ~/.bashrc, then run nvm use –lts.

Pankaj Kumar
Pankaj Kumar

Pankaj Kumar is the founder and CEO of CodeForGeek, with more than 14 years in IT. He is an open-source enthusiast who enjoys sharing what he learns through CodeForGeek and YouTube, with a focus on Python, data analytics, machine learning, Angular, Node.js, and Kafka.

Articles: 337