How to Install Node.js and npm on Ubuntu 24.04

By 

Updated on

6 min read

Install Node.js and npm on Ubuntu 24.04

When you install JavaScript tools on Ubuntu, you usually need both Node.js and npm. Node.js runs JavaScript outside the browser, while npm installs packages and manages project dependencies.

This guide shows three ways to install Node.js and npm on Ubuntu 24.04:

  • Ubuntu repository - The quickest method. Ubuntu 24.04 includes Node.js v18.19.1 and npm 9.2.0.
  • NodeSource repository - Install a specific Node.js version. NodeSource supports Node.js v24.x, v22.x, and v20.x.
  • nvm (Node Version Manager) - Manage multiple Node.js versions on the same machine. This is the preferred method for developers.

Choose the method that fits your project. If you are installing a packaged server application, the Ubuntu repository may be enough. If you need a current upstream LTS release or multiple Node.js versions, use NodeSource or nvm.

Quick Reference

TaskCommand
Install Node.js and npm from Ubuntusudo apt install nodejs npm
Install current LTS via NodeSourcesudo apt install nodejs (after adding repo)
Install via nvmnvm install --lts
Check Node.js versionnode -v
Check npm versionnpm -v
List installed versions (nvm)nvm ls
Switch Node.js version (nvm)nvm use <version>
Set default version (nvm)nvm alias default <version>
Uninstall Node.jssudo apt remove nodejs or nvm uninstall <version>

Which Method Should You Use?

Use the Ubuntu repository when you want the simplest system package and do not need the latest Node.js release. This method installs both nodejs and npm with one command.

Use NodeSource when you want a newer upstream LTS release installed system-wide through APT. This is a good choice for servers where Node.js should be managed like other system packages.

Use nvm when you develop JavaScript applications and need to switch between Node.js versions per project. nvm installs Node.js in your user account and does not require sudo.

Installing Node.js and npm from the Ubuntu Repository

Ubuntu 24.04 includes Node.js and npm in its default repositories. This is the fastest way to install both tools:

Terminal
sudo apt update
sudo apt install nodejs npm

Verify the installation:

Terminal
node -v
output
v18.19.1
Terminal
npm -v
output
9.2.0

Ubuntu maintains its package builds through the Ubuntu security update process, but the upstream Node.js 18 release line is end-of-life. If your application requires an upstream-supported Node.js version, use NodeSource or nvm instead.

To compile native addons from npm packages, install the build tools:

Terminal
sudo apt install build-essential

Installing Node.js and npm from NodeSource

NodeSource maintains an APT repository with current Node.js release lines. Use this method when you want a newer system-wide Node.js version than the one in the Ubuntu repository.

Install the required packages:

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

Import the NodeSource GPG key:

Terminal
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

NodeSource provides the following versions:

  • v24.x - LTS version (Krypton).
  • v22.x - LTS version (Jod).
  • v20.x - Maintenance LTS.

This example installs Node.js 24.x. Change NODE_MAJOR=24 to another supported release line if your application requires it:

Terminal
NODE_MAJOR=24
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

Install Node.js:

Terminal
sudo apt update
sudo apt install nodejs

The NodeSource nodejs package includes both the node and npm commands.

Verify the installation:

Terminal
node --version
output
v24.15.0
Terminal
npm --version
output
11.12.1

After npm is installed, see the npm command guide for package installs, updates, scripts, and lock-file based installs.

To compile native addons from npm, install the development tools:

Terminal
sudo apt install build-essential

Installing Node.js and npm using nvm

nvm (Node Version Manager) is a Bash script that lets you manage multiple Node.js versions per user. This is the preferred method for developers who need to switch between versions.

Download and install nvm:

Terminal
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

Do not use sudo , as it will enable nvm for the root user only.

The script clones the repository to ~/.nvm and adds the required lines to your shell profile:

output
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Either close and reopen your terminal or run the commands above to load nvm in the current session.

Verify the installation:

Terminal
nvm -v
output
0.40.3

Install the latest LTS version:

Terminal
nvm install --lts
output
Installing latest LTS version.
Now using node v24.15.0 (npm v11.12.1)

Verify the installation:

Terminal
node -v
output
v24.15.0

Check npm:

Terminal
npm -v
output
11.12.1

Install additional Node.js versions when needed:

Terminal
nvm install 22
nvm install 20

List installed versions:

Terminal
nvm ls
output
      v20.20.2
      v22.22.2
->    v24.15.0

The arrow marks the active version. The default version activates when opening new shells.

Switch to a different version:

Terminal
nvm use 22

Change the default version:

Terminal
nvm alias default 24

Troubleshooting

npm: command not found
Install npm from the Ubuntu repository with sudo apt install npm, or install Node.js from NodeSource or nvm. The NodeSource and nvm methods include npm with Node.js.

node: command not found
Check whether the package installed correctly with dpkg -l nodejs if you used APT. If you used nvm, close and reopen your terminal, or load nvm in the current shell:

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

Ubuntu installed an old Node.js version
The Ubuntu repository version is stable but older than the current upstream LTS release. Use NodeSource for a newer system-wide version, or use nvm if you need per-project versions.

Permission errors with global npm packages
Avoid running npm global installs with sudo unless you understand the security and file ownership impact. For development machines, nvm is usually the cleaner option because global packages are installed under your user account.

nvm works in one terminal but not another
Make sure the nvm initialization lines were added to the shell file you actually use, such as ~/.bashrc, ~/.zshrc, or ~/.profile.

Uninstalling Node.js

The uninstall method depends on how you installed Node.js.

NodeSource or Ubuntu repository:

Terminal
sudo apt remove nodejs npm
sudo apt autoremove

If you used NodeSource, you can also remove the repository file:

Terminal
sudo rm /etc/apt/sources.list.d/nodesource.list
sudo apt update

nvm:

Terminal
nvm uninstall 24

To completely remove nvm, delete the ~/.nvm directory and remove the nvm lines from your shell configuration file. Run the following command only when you no longer need any Node.js versions installed through nvm:

Terminal
rm -rf ~/.nvm

Conclusion

For supported release lines and end-of-life dates, see the official Node.js releases page .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page