nod.js

How To Install an Upstream Version of Node.js on Ubuntu 24.04

If you’re diving into the world of JavaScript and Node.js development, you might find that the version available in your Ubuntu 24.04 repository isn’t the latest one. Fortunately, installing an upstream version of Node.js is a straightforward process that allows you to take advantage of the latest features, improvements, and security patches. In this blog post, we’ll walk you through the steps to install the upstream version of Node.js on your Ubuntu system.

Prerequisites

To successfully install Node.js, you need:

  • A server or computer running Ubuntu 24.04.
  • A user with sudo privileges to run command-line operations.
  • An internet connection for downloading the Node.js binaries.

Step 1: Update System Packages

Before installing any new software, it’s a good idea to ensure your package list is up to date. Open your terminal and run:

sudo apt update
sudo apt upgrade -y

This command fetches the latest list of packages and their versions. The -y flag automatically confirms any prompts to install the updates.

Step 2: Install Required Dependencies

Node.js installation may require certain build tools. Install the essential packages with:

sudo apt install -y build-essential curl

build-essential is a package that contains various tools for building software, while curl is a command-line tool for transferring data with URLs.

Step 3: Download Node.js

The fastest way to install the latest version of Node.js is to use the NodeSource repository. NodeSource maintains an up-to-date repository of Node.js binaries. First, you’ll want to grab the setup script for the version you want. At the time of writing, the latest version is Node.js v20.x. You can check the Node.js official website for the latest version.

To add the NodeSource repository, run:

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

Replace 20.x with the version number you wish to install. This command will download and execute the NodeSource installation script, which will set up the repository for you.

Step 4: Install Node.js

Now that you have the NodeSource repository set up, you can install Node.js with:

sudo apt install -y nodejs

This command installs Node.js along with npm (Node Package Manager), which is essential for managing your JavaScript packages.

Step 5: Verify Installation

To ensure that Node.js was installed correctly, check the version installed by running:

node -v

You should see the version number of Node.js printed in the terminal.

Similarly, check npm’s version:

npm -v

Both commands should return the version numbers, confirming that the installation was successful.

Step 6: (Optional) Install nvm (Node Version Manager)

If you anticipate needing multiple versions of Node.js for different projects, you might consider installing nvm (Node Version Manager). With nvm, you can easily install, manage, and switch between different versions of Node.js.

To install nvm, run:

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

After installation, you will need to close and reopen the terminal—or source your profile script like so:

source ~/.bashrc

You can then check if nvm is installed by running:

nvm --version

Conclusion

You’ve successfully installed the upstream version of Node.js on Ubuntu 24.04! With this powerful runtime environment at your disposal, you can now start building server-side applications or experimenting with your favorite JavaScript library. As always, keep your Node.js installation updated, and don’t hesitate to explore the Node.js documentation to discover new features and capabilities.

Happy coding from all of us at Greenhost.Cloud!