Node.js enables developers to run JavaScript outside the browser, transforming it from a client-side scripting language into a full-stack development platform. Whether you need to build REST APIs, create real-time chat applications, develop command-line tools, or run build systems like webpack and gulp, Node.js provides the runtime environment to make it happen. Once Node.js is installed, you can also install TypeScript on Ubuntu for type-safe development. By the end of this guide, you will have Node.js installed on Ubuntu with a verified working setup, ready for development.
Choose Your Node.js Installation Method
Ubuntu offers several ways to install Node.js, each with different trade-offs between convenience, version control, and update management. The following table summarizes your options:
| Method | Channel | Version | Updates | Best For |
|---|---|---|---|---|
| Ubuntu Repository | Ubuntu Repos | Distribution default | Automatic via apt upgrade | Users who prefer stability over latest features |
| NodeSource Repository | NodeSource | Latest LTS or Current | Automatic via apt upgrade | Developers needing specific Node.js versions |
| Node Version Manager (NVM) | NVM GitHub | Any available version | Manual via nvm install | Developers managing multiple Node.js versions per project |
For most users, the Ubuntu repository method is recommended because it integrates with system updates and requires no additional configuration. Choose NodeSource when you need a specific Node.js version not available in the default repositories, or NVM when you frequently switch between Node.js versions across different projects.
This guide supports Ubuntu 22.04 LTS, 24.04 LTS, and 26.04 LTS installations. The NodeSource repository provides packages for all supported Ubuntu LTS releases, while NVM works across all Linux distributions regardless of version. Commands shown work identically on all supported LTS releases.
Update Ubuntu Before Node.js Installation
Before installing Node.js, refresh your package index to ensure you install the latest available version. This step also applies any pending security updates that may affect package dependencies:
sudo apt update && sudo apt upgrade
Method 1: Install Node.js from Ubuntu Repository
The Ubuntu repository provides a stable Node.js version that receives security updates through the standard system update process. This method requires no additional configuration and works immediately after installation.
Install Node.js using the default package manager:
sudo apt install nodejs npm
Verify the installation by checking the installed version:
node --version
npm --version
Expected output varies by Ubuntu release:
# Ubuntu 26.04 LTS v20.19.4 9.2.0 # Ubuntu 24.04 LTS v18.19.1 9.2.0 # Ubuntu 22.04 LTS v12.22.9 8.5.1
The Ubuntu repository separates Node.js and npm into distinct packages, so both must be installed explicitly. This version is suitable for many use cases, but developers working with modern JavaScript frameworks may need a newer version. If your project requires Node.js 18 LTS or later on Ubuntu 22.04, continue to Method 2 for the NodeSource repository.
Method 2: Install Node.js from NodeSource Repository
NodeSource maintains official Node.js packages that provide access to the latest LTS and Current releases. This method gives you control over which major version to install while still receiving automatic security updates through APT.
Install Prerequisites
First, install the packages required for downloading and verifying the NodeSource repository:
sudo apt install curl gnupg ca-certificates
Import NodeSource GPG Key
Download and store the NodeSource GPG key to verify package authenticity. First, create the keyrings directory if it does not exist:
sudo install -m 0755 -d /etc/apt/keyrings
Next, download the GPG key and convert it to the binary format APT requires:
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
Add NodeSource Repository
Create the repository configuration file. Set the NODE_MAJOR variable to your desired major version before running the command:
NODE_MAJOR=24
cat <<EOF | sudo tee /etc/apt/sources.list.d/nodesource.sources
Types: deb
URIs: https://deb.nodesource.com/node_$NODE_MAJOR.x
Suites: nodistro
Components: main
Signed-By: /etc/apt/keyrings/nodesource.gpg
EOF
Choose from the currently supported Node.js versions:
NODE_MAJOR=20: Maintenance LTS release supported until April 2026NODE_MAJOR=22: Maintenance LTS release (Jod) supported until April 2027NODE_MAJOR=24: Active LTS release (Krypton, recommended for new projects)NODE_MAJOR=25: Current release with latest features and shorter support window
Node.js 24 (Krypton) is the current Active LTS release and recommended for most new projects. Choose Node.js 22 or 20 if your existing project requires them. Check the Node.js releases page for current support schedules.
Install Node.js from NodeSource
Update the package index to include the new repository, then install Node.js:
sudo apt update
sudo apt install nodejs
The NodeSource package includes both the Node.js runtime and npm (Node Package Manager). Verify both are installed correctly:
node --version
npm --version
Expected output for Node.js 24:
v24.12.0 11.6.2
Method 3: Install Node.js with Node Version Manager (NVM)
NVM allows you to install multiple Node.js versions side by side and switch between them instantly. This approach is ideal for developers working on multiple projects with different Node.js requirements, or for testing code against multiple versions.
Install NVM
Download and run the NVM installation script. You can use either curl or wget:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
Alternatively, if you prefer wget:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
The installation script adds NVM to your shell configuration. Load NVM into your current session without restarting the terminal:
source ~/.bashrc
Verify NVM is available:
nvm --version
0.40.3
List Available Node.js Versions
Before installing, view all available Node.js versions:
nvm ls-remote
This command displays every available Node.js version, including LTS releases marked with codenames. To filter for LTS versions only:
nvm ls-remote --lts
Install a Node.js Version
Install the latest LTS version with a single command:
nvm install --lts
Alternatively, install a specific version by number:
nvm install 24
Example output:
Downloading and installing node v24.12.0... Downloading https://nodejs.org/dist/v24.12.0/node-v24.12.0-linux-x64.tar.xz... ######################################################### 100.0% Computing checksum with sha256sum Checksums matched! Now using node v24.12.0 (npm v11.6.2)
Verify the installation:
node --version
v24.12.0
Switch Between Node.js Versions
NVM makes switching between installed versions instant. First, install an additional version:
nvm install 20
Switch to a different installed version:
nvm use 20
Now using node v20.19.0 (npm v10.8.2)
To set a default version that persists across terminal sessions:
nvm alias default 24
View all installed versions and see which is currently active:
nvm ls
-> v20.19.0
v24.12.0
default -> 24 (-> v24.12.0)
node -> stable (-> v24.12.0) (default)
stable -> 24.12 (-> v24.12.0) (default)
lts/* -> lts/krypton (-> v24.12.0)
Troubleshoot Node.js Installation
Command Not Found After NVM Installation
If nvm returns “command not found” after installation, your shell configuration was not reloaded. Either restart your terminal or manually source your shell configuration:
source ~/.bashrc
For Zsh users, source the Zsh configuration instead:
source ~/.zshrc
Permission Denied During Global npm Install
If you receive “EACCES: permission denied” when installing global npm packages with the Ubuntu repository version, do not use sudo with npm. Instead, configure npm to use a user-writable directory:
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
Alternatively, using NVM or NodeSource eliminates this issue entirely because they install to user-writable directories or handle permissions correctly.
NodeSource Repository Key Errors
If APT reports GPG key errors when updating the NodeSource repository, verify the key exists and has correct permissions:
ls -la /etc/apt/keyrings/nodesource.gpg
Expected output showing the key file exists with read permissions:
-rw-r--r-- 1 root root 2794 Dec 17 12:00 /etc/apt/keyrings/nodesource.gpg
If the file is missing, re-run the GPG key import command from Method 2.
Remove Node.js
The removal process depends on which installation method you used.
Remove Node.js Installed via APT
If you installed Node.js from the Ubuntu repository or NodeSource, remove it with APT:
sudo apt remove nodejs
sudo apt autoremove
The autoremove command cleans up any dependencies that were installed alongside Node.js and are no longer needed.
If you used NodeSource, also remove the repository configuration:
sudo rm /etc/apt/sources.list.d/nodesource.sources
sudo rm /etc/apt/keyrings/nodesource.gpg
sudo apt update
Verify Node.js is removed:
node --version
bash: node: command not found
Remove Node.js Installed via NVM
When using NVM, you can remove individual Node.js versions or uninstall NVM entirely.
Check which version is currently active:
nvm current
Deactivate the current version before removing it:
nvm deactivate
Uninstall a specific Node.js version:
nvm uninstall 24
To completely remove NVM and all installed Node.js versions, delete the NVM directory:
Warning: The following command permanently deletes NVM and all Node.js versions installed through it. Any globally installed npm packages will also be removed.
rm -rf ~/.nvm
Remove the NVM initialization lines from your shell configuration by editing ~/.bashrc and removing the lines that reference NVM (typically at the end of the file).
Conclusion
You now have Node.js installed and verified on Ubuntu, ready for JavaScript development. The Ubuntu repository provides the simplest path with automatic updates, NodeSource delivers specific version control with package manager integration, and NVM offers maximum flexibility for multi-project development. For a complete development environment, consider pairing Node.js with Visual Studio Code on Ubuntu, which provides excellent JavaScript and TypeScript tooling. Whichever method you chose, you can now run JavaScript applications, install npm packages, and build modern web applications on your Ubuntu system.