How to 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.1and npm9.2.0. - NodeSource repository - Install a specific Node.js version. NodeSource supports Node.js
v24.x,v22.x, andv20.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
| Task | Command |
|---|---|
| Install Node.js and npm from Ubuntu | sudo apt install nodejs npm |
| Install current LTS via NodeSource | sudo apt install nodejs (after adding repo) |
| Install via nvm | nvm install --lts |
| Check Node.js version | node -v |
| Check npm version | npm -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.js | sudo 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:
sudo apt update
sudo apt install nodejs npmVerify the installation:
node -vv18.19.1npm -v9.2.0Ubuntu 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:
sudo apt install build-essentialInstalling 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:
sudo apt update
sudo apt install ca-certificates curl gnupgImport the NodeSource GPG key:
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.gpgNodeSource 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:
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.listInstall Node.js:
sudo apt update
sudo apt install nodejsThe NodeSource nodejs package includes both the node and npm commands.
Verify the installation:
node --versionv24.15.0npm --version11.12.1After 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:
sudo apt install build-essentialInstalling 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:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bashDo 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:
=> 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_completionEither close and reopen your terminal or run the commands above to load nvm in the current session.
Verify the installation:
nvm -v0.40.3Install the latest LTS version:
nvm install --ltsInstalling latest LTS version.
Now using node v24.15.0 (npm v11.12.1)Verify the installation:
node -vv24.15.0Check npm:
npm -v11.12.1Install additional Node.js versions when needed:
nvm install 22
nvm install 20List installed versions:
nvm ls v20.20.2
v22.22.2
-> v24.15.0The arrow marks the active version. The default version activates when opening new shells.
Switch to a different version:
nvm use 22Change the default version:
nvm alias default 24Troubleshooting
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:
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:
sudo apt remove nodejs npm
sudo apt autoremoveIf you used NodeSource, you can also remove the repository file:
sudo rm /etc/apt/sources.list.d/nodesource.list
sudo apt updatenvm:
nvm uninstall 24To 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:
rm -rf ~/.nvmConclusion
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 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