Home  »  ArticlesGuidesHow ToLibrariesSoftwareTechnologyTools   »   How to Install Node.js on Ubuntu 24.04 Noble Numbat

How to Install Node.js on Ubuntu 24.04 Noble Numbat

Node.js is a powerful JavaScript runtime built on Chrome’s V8 engine, commonly used for building fast, scalable network applications. It has become a popular choice for both frontend and backend development due to its efficiency and extensive ecosystem. In this blog post, we’ll guide you through the process of installing Node.js on Ubuntu 24.04 Noble Numbat.

Prerequisites

Before you begin, make sure your system is up-to-date and you have administrative privileges. Open your terminal and execute the following commands:

$ sudo apt update
$ sudo apt upgrade

Step-by-Step Installation Guide

There are multiple ways to install Node.js on Ubuntu 24.04. We’ll cover the most common methods: using the NodeSource repository, the official Ubuntu repository, and nvm (Node Version Manager).

Method 1: Using NodeSource Repository

The NodeSource repository provides the most up-to-date version of Node.js. This is the recommended method for most users.

Step 1: Add NodeSource Repository

First, add the NodeSource repository for the latest LTS version of Node.js:

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

Step 2: Install Node.js

Next, install Node.js using the following command:

$ sudo apt install -y nodejs

Step 3: Verify the Installation

To ensure Node.js is installed correctly, check the version:

$ node -v

You should see the version number of Node.js. Additionally, verify npm (Node Package Manager) is installed:

$ npm -v

Method 2: Using the Official Ubuntu Repository

This method is straightforward but may not provide the latest version of Node.js.

Step 1: Install Node.js

Install Node.js from the official Ubuntu repositories:

$ sudo apt install -y nodejs

Step 2: Install npm

If npm is not included by default, you can install it separately:

$ sudo apt install -y npm

Step 3: Verify the Installation

Check the installed versions of Node.js and npm:

$ node -v
$ npm -v

Method 3: Using Node Version Manager (nvm)

nvm is a popular tool for managing multiple versions of Node.js on a single system. This is ideal for developers who need to test their applications with different Node.js versions.

Step 1: Install nvm

Download and install nvm using the following curl command:

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

After the installation, add nvm to your shell profile. This is typically done automatically, but you can manually add the following lines to your ~/.bashrc, ~/.zshrc, or other shell profile files if needed:

$ 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

Reload your shell configuration:

$ source ~/.bashrc

Step 2: Install Node.js

With nvm installed, you can now install Node.js. To install the latest LTS version, use:

$ nvm install --lts

You can also install a specific version by replacing --lts with the desired version number, such as 14.17.0.

Step 3: Verify the Installation

Ensure Node.js and npm are installed correctly:

$ node -v
$ npm -v

Managing Node.js Versions with nvm

One of the advantages of using nvm is the ability to switch between different Node.js versions easily.

List Installed Versions

To list all installed versions of Node.js:

$ nvm ls

List Available Versions

To list all available versions of Node.js that can be installed:

$ nvm ls-remote

Use a Specific Version

To switch to a different installed version:

$ nvm use <version>

Replace <version> with the version number you want to use, such as 14.17.0.

Set Default Version

To set a default Node.js version to be used in all new shell sessions:

$ nvm alias default <version>

Replace <version> with the version number you want to set as the default.

Conclusion

Installing Node.js on Ubuntu 24.04 Noble Numbat is a straightforward process with multiple methods available to suit different needs. Whether you choose the NodeSource repository for the latest version, the official Ubuntu repository for simplicity, or nvm for flexibility in managing multiple versions, this guide provides all the steps necessary to get Node.js up and running.

By following this comprehensive guide, you can leverage the power of Node.js to build scalable and efficient applications on your Ubuntu system.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.