How to Install Node on Ubuntu 24.04

How to Install Node on Ubuntu 24.04

Node or NodeJS, a popular open-source JavaScript runtime environment, is a key tool for web developers. It’s commonly used to enhance web app functionality or create local development environments. It is an environment that enables web developers to write JavaScript that interacts with various parts of the outside world other than the browser. In this tutorial, you will be guided on how to install Node on Ubuntu 24.04 using the default repository and NodeSource. You will also get to learn how to install a specific version of Node using NVM.

Prerequisites

# – It's important to execute the commands with root privileges, either by being logged in as the root user or by utilizing the sudo command.
$ – Make sure to execute these commands as a regular user

Install Node from APT

This is the easiest and fastest method of installing Node on our Ubuntu 24.04 system. Let’s run the command below to do so.

$ sudo apt install curl apt-transport-https ca-certificates gnupg

Once the dependencies are installed, we can proceed with this command below.

$ sudo apt install nodejs -y

Once completed, we can verify and check the Node version installed.

$ nodejs -v

The command will return an output like this:

v18.19.1

Install Node using NVM

Node Version Manager or NVM is a bash script to manage several NodeJS versions installation on your Ubuntu machine. By using this script, users are able to install and maintain different versions of Node.

First, let’s download the script.

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

The command above will print you an output like this:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload Upload Total Spent Left Speed
100 16555 100 16555 0 0 107k 0 --:--:-- --:--:-- --:--:-- 107k
=> Downloading nvm from git to '/home/admins/.nvm'
=> Cloning into '/home/admins/.nvm'...
remote: Enumerating objects: 365, done.
remote: Counting objects: 100% (365/365), done.
remote: Compressing objects: 100% (313/313), done.
remote: Total 365 (delta 43), reused 168 (delta 26), pack-reused 0
Receiving objects: 100% (365/365), 365.09 KiB | 2.90 MiB/s, done.
Resolving deltas: 100% (43/43), done.
* (HEAD detached at FETCH_HEAD)
master
=> Compressing and cleaning up git repository

=> Appending nvm source string to /home/admins/.bashrc
=> Appending bash_completion source string to /home/admins/.bashrc
=> 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

Make sure to source the bash script before can use it.

$ source ~/.bashrc

Now, at this point, we should be able to list the Node version we can install.

$ nvm list-remote

You will see a very long list of Node versions you can choose to install. This is just an excerpt:

    v20.0.0
    v20.1.0
    v20.2.0
    v20.3.0
    v20.3.1
    v20.4.0
    v20.5.0
    v20.5.1
    v20.6.0
    v20.6.1
    v20.7.0
    v20.8.0
    v20.8.1
    v20.9.0   (LTS: Iron)
   v20.10.0   (LTS: Iron)
   v20.11.0   (LTS: Iron)
   v20.11.1   (LTS: Iron)
   v20.12.0   (LTS: Iron)
   v20.12.1   (LTS: Iron)
   v20.12.2   (LTS: Iron)
   v20.13.0   (LTS: Iron)
   v20.13.1   (LTS: Iron)
   v20.14.0   (Latest LTS: Iron)
    v21.0.0
    v21.1.0
    v21.2.0
    v21.3.0
    v21.4.0
    v21.5.0
    v21.6.0
    v21.6.1
    v21.6.2
    v21.7.0
    v21.7.1
    v21.7.2
    v21.7.3
    v22.0.0
    v22.1.0
    v22.2.0

For example, if you want to install version 22.2.0, you can simply run this command:

$ nvm install 21.0.0
admins@rh:~$ nvm install 21.0.0
Downloading and installing node v21.0.0...
Downloading https://nodejs.org/dist/v21.0.0/node-v21.0.0-linux-x64.tar.xz...
################################################################################################################################################################################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v21.0.0 (npm v10.2.0)

Or, you can also install version 22.2.0

$ nvm install 22.2.0
admins@rh:~$ nvm install 22.2.0
Downloading and installing node v22.2.0...
Downloading https://nodejs.org/dist/v22.2.0/node-v22.2.0-linux-x64.tar.xz...
################################################################################################################################################################################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v22.2.0 (npm v10.7.0)
Creating default alias: default -> 22.2.0 (-> v22.2.0)

The last NodeJS version you install will be the default version. To switch to another version, you can execute this command:

$ nvm use 21.0.0

To verify, you can check the version.

admins@rh:~$ nvm use 21.0.0
Now using node v21.0.0 (npm v10.2.0)
admins@rh:~$ node -v
v21.0.0
admins@rh:~$ nvm use 22.2.0
Now using node v22.2.0 (npm v10.7.0)
admins@rh:~$ node -v
v22.2.0

Install Node from NodeSource

If you’re looking for the most recent version of Node, it’s recommended to install it from the Node repository rather than the Ubuntu default one. NodeSource provides a variety of versions to select from. Simply follow the instructions given to install Node with ease.

First, let’s download and install the source.

$ curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

Next, we need to update the package information of the system.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
$ sudo apt update

Finally, we can install NodeJS.

$ sudo apt install nodejs

That should be it! You have successfully installed the LTS version of Node. This installation method is perfect for you who want to install a specific version of Node or the LTS version.

To install a specific version, for example, version 18, let’s execute this command.

$ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -

Do not forget to update the system’s package information before installing NodeJS version 18.

$ sudo apt update
$ sudo apt install nodejs

Additionally, if you want a version other than 18, simply replace 18 with any number of versions available to install.

That’s it! You have learned how to install Node on Ubuntu 24.04. After following the article above, you should be able to install Node on Ubuntu 24.04. If you have an active server with us and currently have an issue or do not want to spend time installing Node on Ubuntu 24.04 yourself, you can simply contact us through chat or submit a ticket. Our expert administrators are available 24×7 and will respond to your request immediately.

PS. If you liked this post on how to install Nodeon Ubuntu 24.04, please share it with your friends or leave a comment below. Thanks.

Leave a Comment