How to Install Node.js on Ubuntu 24.04
Developers often work with limited time and resources, so they need tools that help them build and scale applications quickly. Node.js is one such solution, designed for fast and flexible application development.
Node.js is widely used in modern web development due to its extensive ecosystem of reusable modules. These ready-made packages help teams avoid building common features from scratch and speed up development. With npm, developers can easily reuse code, automate routine tasks, and manage project dependencies more efficiently.
In this guide, you will learn how to install Node.js on Ubuntu 24.04 LTS.
#Prerequisites
Here’s what you will require before getting started:
-
An instance of Ubuntu 24.04 VPS (this guide was tested on Cherry Servers VPS)
-
SSH access to the server
-
A sudo user already configured. Here’s how to create a sudo user in case you don’t have one created yet
Scalable VPS Hosting
Deploy fast, secure VPS for websites, apps, and dev environments. Scale on demand, manage with full root access, and get 24/7 expert support.
#Installing Node.js on Ubuntu 24.04
There are several ways to install Node.js on Ubuntu 24.04, including the default Ubuntu repositories, NodeSource, and NVM (Node Version Manager). Each method has its own advantages depending on whether you prioritize simplicity, stability, or version control.
#Method 1: Installing from the default repository
Installing Node from the default Ubuntu repositories is the easiest route. Just a single command, and you're done. No extra configuration needed. The catch? You won't get the latest version. The version you get here is outdated and might not be the best fit if you are looking to work with the latest version.
Regardless, the installed version will be just fine for learning purposes.
To install from the default APT repository, first, update the local package index:
sudo apt update
Next, install Node.js from the default APT repositories as follows:
sudo apt install nodejs npm -y
Once the installation finishes, verify that both Node and NPM are available by checking their versions:
node -v && npm -v
You should see something like this in your terminal:
v18.19.1
9.2.0
As you can see, these aren't the latest versions available. If you need to stay current, head to the next installation method.
#Method 2: Installing from NodeSource
When you install Node.js from the standard repositories, the versions usually fall behind by several versions.
NodeSource is the ideal option when you want the latest Node.js version without the hassle of compiling from source or complex setups.
Perks that come with installing Node from NodeSource include:
-
Up-to-date packages — NodeSource stays in sync with official Node.js release lines. When a new release drops, a security patch, or otherwise, it typically shows up in the NodeSource repository within 48 hours, which is far quicker than what default OS repositories can manage.
-
Version flexibility — You're not stuck with whatever version your OS ships. NodeSource lets you pick the exact major version your project needs, which matters more than people realize when dealing with dependency requirements.
-
Broad distribution support — Works across all major Linux distributions without any extra tweaking. No adjusting configs for each new OS version.
-
Simpler installation — The setup boils down to a couple of commands. The required dependencies like glibc and Python3 are already accounted for, so there's nothing extra to configure before you get started.
-
NPM included — No separate install step needed. When you pull Node.js from NodeSource, NPM is automatically included.
To start the installation, download and run the setup script. For this example, we are installing Node version 24. Replace the version number with your preferred version
curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
Next, install Node.js via APT.
sudo apt install nodejs -y
Then confirm the installation by checking the versions:
node -v && npm -v
Outputv24.15.0
11.12.1
If Node.js and npm were previously installed, they will be uninstalled before being installed from NodeSource.
#Method 3: Installing via NVM (Recommended for developers)
NodeSource and default repositories offer a system-wide installation. This implies that all your projects are bound to a single version of Node, leaving no room to switch to a different one. It's a headache for developers handling projects that require different versions, and this is where NVM emerges as the king of the installation options we've covered.
Node Version Manager does exactly what the name suggests: it manages multiple versions of Node.js on the same machine. Need Node 20 for a legacy codebase while your newer project runs on Node 24?. No problem at all. Just install both and switch between them across various projects. No conflicts, no reinstalling.
On the security front, NVM is the preferred choice of all the installation methods. System-wide installation requires running sudo with every npm command, potentially exposing the system to supply-chain attacks.
Installing Node via NVM
To install NVM, head over to the project's GitHub page and scroll to the Installing and Updating section in the README page. You'll find curl and wget commands there — pick whichever you prefer and run it in your terminal.
For cURL
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
For wget
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
Running either of the commands shown downloads a script and clones the nvm repository to the ~/.nvm folder in your home directory. Once done, source the ~/.bashrc file.
source ~/.bashrc
You can now start running NVM commands. For example, to check the version installed, run the command:
nvm --version
At the time of installation, this is the latest version:
Output0.40.4
With NVM installed, let’s now install Node. To list all the available versions that you can install, run the command:
Outputnvm ls-remote
This lists all the versions from the earliest to the latest. To install the latest version from the official servers, run the command
nvm install node
This downloads and installs Node v25.9.0, which is the latest version at the time of publishing the guide.
OutputDownloading and installing node v25.9.0...
Downloading https://nodejs.org/dist/v25.9.0/node-v25.9.0-linux-x64.tar.xz...
##############################################################################################
Computing checksum with sha256sum
Checksums matched!
Now using node v25.9.0
Creating default alias: default -> node (-> v25.9.0 *)
To install a specific Node version, e.g., Node v22, run:
nvm install 22
To install Node version 24, run:
nvm install 24
You can install as many Node versions as you can, depending on various project requirements.
Verifying Node version installed
Your environment might have multiple versions of Node installed. To list the current active version, run the command:
nvm current
In this case, Node v22.22.2 is the current version in my shell session.
Outputv22.22.2
To list all installed versions of Node, run:
nvm ls
In addition, it shows the following:
-
The currently active version.
-
The default version (alias) if configured.
Here’s some sample output:
Output-> v22.22.2
v20.20.2
v25.9.0
default -> 25.9.0 (-> v25.9.0 *)
iojs -> N/A (default)
node -> stable (-> v25.9.0 *) (default)
stable -> 25.9 (-> v25.9.0 *) (default)
Let’s break this down:
-
-> v22.22.2- The symbol (->) shows the currently active version, in this casev22.22.2. -
(v20.20.2, and v25.9.0)- Other installed Node versions in the system, but not currently in use. -
default -> v25.9.0- The version that loads automatically upon opening a new terminal shell. -
node -> stable (-> v25.9.0 *) (default)- This is the current stable version. In this case,v25.9.0. -
stable -> 25.9 (-> v25.9.0 *) (default)- An alias for the current stable version.
Switching between Node versions
To switch to a specific version, run the nvm use command followed by the version number:
For example, to switch to Node 24.15, run:
nvm use 24
You will get a confirmation about the version switch (not just for Node, but for the npm version associated with it).
OutputNow using node v24.15.0 (npm v11.12.1)
NVM requires you to download and install a specific Node.js version before you can switch to it. For example, if you installed Node v24 via NodeSource, you can't switch to it unless you downloaded and installed it via NVM.
To set a default version, run the nvm alias default command followed by the version number.
nvm alias default 24
Outputdefault -> 24 (-> v24.15.0)
Just to be sure, you can verify the default version by checking Node’s version.
Outputnode -v
#Conclusion
Installing Node.js comes down to picking the right method for your use case. The default repository is the quickest route, but lags behind the official release. NodeSource bridges that gap by giving you access to the latest stable builds for any major version, with broad distribution support and no compilation required.
For most developers, NVM is the ideal installation method. It solves the version-locking problem introduced by system-wide installations, letting you run different versions of Node.js across projects without conflicts.
Starting at just $3.51 / month, get virtual servers with top-tier performance.