How to Install Node.js on Ubuntu
Node.js is an open-source, cross-platform runtime environment that allows you to run JavaScript outside of a browser — commonly used for building fast, scalable server-side and networking applications.
This guide walks you through installing Node.js on Ubuntu 20.04, 22.04, or later.
Step 1: Update System Packages
Before installing anything, update your package index:
Step 2: Install Node.js Using APT (Default Ubuntu Repo)
Ubuntu includes Node.js in its default repositories. You can install it directly with:
Then, check the installed version:
However, this version may be outdated. If you want the latest stable version, follow the next method using NodeSource.
Alternative: Install Latest Node.js Using NodeSource
NodeSource provides official up-to-date Node.js binaries for most distributions.
Step 2A: Install curl (if not already installed)
Step 2B: Download the Node.js Setup Script
Choose your desired version, like 18.x
(LTS) or 20.x
(Current):
Step 2C: Install Node.js and npm
Check versions to confirm:
npm
(Node Package Manager) comes bundled with Node.js.
Step 3 (Optional): Install build-essential
for Compiling Native Add-ons
Some npm packages require build tools:
Step 4: Test Node.js
You can run a simple Node.js command to verify everything is working:
Then, in the Node.js REPL (interactive shell), type:
You should see the output:
Type .exit
to leave the REPL.
Optional: Uninstall Node.js
If you ever need to remove Node.js:
Bonus: Install n
– Node Version Manager (Alternative Method)
n
allows you to manage multiple versions of Node.js.
Install it using npm:
Then install the latest Node version:
Or the LTS version:
To switch between installed versions, just use:
Done!
You now have Node.js and npm installed on your Ubuntu system, and you're ready to build and run JavaScript applications on the backend!