4 min read

A Step-by-Step Guide to Installing Node.js on Ubuntu 24.04 LTS

Need Node.js on Ubuntu 24.04 LTS? Skip the default repos and use NVM instead. It's the smart way to manage multiple Node versions for different projects. Here's how to get it set up right, step by step.

J

Jamie

LogicCore Digital

A Step-by-Step Guide to Installing Node.js on Ubuntu 24.04 LTS

So you're setting up a development environment on Ubuntu 24.04 LTS and you need Node.js. You could grab it from Ubuntu's default repositories, but here's the thing - that's usually not the best move. Why? Because you'll likely end up needing different Node.js versions for different projects, and managing that with the system package manager is a pain.

Enter NVM (Node Version Manager). It's the tool that lets you install and switch between multiple Node.js versions effortlessly. Whether you're working on a legacy project that needs Node 18 or a shiny new one that requires the latest LTS, NVM makes it trivial. Plus, it keeps everything isolated from your system packages, which means fewer headaches down the road.

Let's walk through getting Node.js installed on Ubuntu 24.04 LTS the right way.

What You'll Need

Before we dive in, make sure you've got these basics covered:

  • Ubuntu 24.04 LTS: Obviously, you need a working Ubuntu 24.04 LTS installation.
  • Terminal Access: Open it with Ctrl+Alt+T or search for "Terminal" in your applications.
  • Sudo Privileges: Your user account needs administrator rights to install packages.
  • Internet Connection: You'll be downloading NVM and Node.js, so a stable connection is essential.
  • Basic Terminal Comfort: If you can navigate directories and run commands, you're good to go.

Step 1: Update Your Package List

Always a good practice - update your system's package list before installing anything new. This ensures you're working with the latest package information and dependencies.

Open your Terminal and run:

bash
sudo apt update

Enter your password when prompted. This refreshes the list of available packages from your configured repositories.

Step 2: Install Build Tools

NVM sometimes needs to compile Node.js from source, especially if you're installing specific versions. To make that process smooth, we need the essential build tools.

Run this command to install build-essential (includes GCC, G++, make), libssl-dev (for SSL support), and curl (for downloading the NVM script):

bash
sudo apt install build-essential libssl-dev curl -y

The -y flag automatically confirms the installation, so you won't be prompted to approve each package.

Step 3: Install NVM

NVM is a bash script that manages multiple Node.js versions. We'll download and run the official installation script directly.

Important: Check the NVM GitHub repository for the latest version number. As of writing, the command looks like this, but the version tag might have changed:

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

(Replace v0.39.7 with the latest version tag from the NVM GitHub page if needed.)

This command uses curl to fetch the installation script and pipes it directly to bash for execution. The script installs NVM into ~/.nvm and automatically adds configuration lines to your shell profile (~/.bashrc, ~/.zshrc, etc.) so NVM loads every time you open a terminal.

Step 4: Load NVM in Your Current Session

The installation script modified your shell config, but those changes won't take effect until you reload it or open a new terminal window.

To apply the changes right now in your current session, run:

bash
source ~/.bashrc

(Use ~/.zshrc if you're using Zsh instead of Bash.)

Alternatively, just close and reopen your terminal window.

Verify NVM installed correctly:

bash
command -v nvm

If you see nvm printed, you're golden. If nothing shows up or you get an error, double-check that the previous steps completed successfully, especially that the configuration was added to your ~/.bashrc file.

Step 5: Install Node.js with NVM

Now the fun part - actually installing Node.js. NVM makes this straightforward.

For most projects, you'll want the latest LTS (Long-Term Support) version. It's stable, well-tested, and widely supported:

bash
nvm install --lts

NVM will download, compile (if needed), and install the latest LTS release. It also automatically installs the matching npm version, so you get both tools in one go.

Want to see all available versions? Run:

bash
nvm ls-remote

This spits out a long list of every Node.js version you can install.

If you need a specific version (maybe your project requires Node 20.10.0), install it like this:

bash
nvm install 20.10.0

(Replace 20.10.0 with whatever version you need.)

Step 6: Set Your Default Node.js Version

When you install a Node.js version with NVM, it becomes active in your current terminal session. But if you want that version to be the default for every new terminal you open, set an alias.

For the LTS version you just installed:

bash
nvm alias default lts

Or if you installed a specific version and want that as your default:

bash
nvm alias default 20.10.0

Now every new terminal session will automatically use this default version. You can still switch versions temporarily in a session using nvm use <version> (e.g., nvm use 18.17.1).

Step 7: Verify Everything Works

Time to confirm Node.js and npm are installed and working correctly.

Check your Node.js version:

bash
node -v

You should see something like v20.11.1 (the exact version depends on what you installed).

Check your npm version:

bash
npm -v

This should show the corresponding npm version, like 10.2.4.

Run a quick test to make sure Node.js executes properly:

bash
node -e "console.log('Hello from Node.js on Ubuntu 24.04!');"

If you see "Hello from Node.js on Ubuntu 24.04!" printed, everything is working perfectly.

You're All Set

That's it! You've got Node.js and npm installed on Ubuntu 24.04 LTS using NVM. This setup gives you the flexibility to manage multiple Node.js versions, which is invaluable when you're juggling different projects with different requirements. You're ready to start building.

Helpful Resources

Want to dive deeper? These official resources are worth bookmarking:

Published on April 21, 2025