Getting Node.js 24 running on Ubuntu 24 should be a straightforward process. While Ubuntu comes with a version of Node.js in its default repositories, you might want to use Node.js 24, which will be LTS in October 2025. This guide offers two simple methods to get you set up quickly.
We'll cover a one-liner script that automates everything, including setting up a proper global prefix for npm and enabling Yarn and pnpm via Corepack. For those who prefer manual control, we'll also walk through each step in detail.
I've created a script, so you can install everything by running a single command. This script will set up Node.js 24, configure a global npm prefix (so you don't need sudo
for global packages), and optionally enable corepack
(for Yarn and pnpm) and install Bun.
Just open your terminal and run this:
curl -fsSL https://angelblanco.dev/scripts/ubuntu-install-node-24.sh | bash
The script will ask for confirmation at each major step, so you still have control over what gets installed. You can also review the full script content before running it or customize it for your own needs.
If you dont have curl
installed:
sudo apt update
sudo apt instal curl
For those who prefer a hands-on approach, here’s a breakdown of what the script does. You can follow these steps to perform the installation manually.
First, we need to make sure our system has the necessary tools to fetch and install Node.js.
sudo apt update
sudo apt install -y ca-certificates curl gnupg
Next, we'll add the NodeSource repository, which is a trusted source for up-to-date Node.js versions on Debian and Ubuntu.
curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
With the repository in place, installing Node.js is as simple as running:
sudo apt-get install -y nodejs
This command installs both the node
runtime and the npm
package manager.
By default, npm
installs global packages in a system directory that requires sudo
. This can lead to permission issues down the line. To avoid this, it's a best practice to configure a local directory for your global packages.
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
You'll also need to add this directory to your PATH
. Open your ~/.bashrc
or ~/.zshrc
file and add the following line:
export PATH=~/.npm-global/bin:$PATH
Corepack is an experimental tool included with Node.js that simplifies managing different package managers. With it, you don't need to install Yarn or pnpm manually.
To enable it, just run:
sudo corepack enable
Now you can use yarn
and pnpm
in your projects without any extra installation steps.
Bun is a fast, all-in-one JavaScript toolkit that has been gaining a lot of traction. If you want to give it a try, you can install it with its official script:
curl -fsSL https://bun.sh/install | bash
This is the complete script that automates the steps above. It includes confirmations and handles temporary files, making the process smooth and safe.
#!/bin/bash
#
# Author: Ángel Blanco
# License: MIT
#
# This script is provided "as is", without warranty of any kind. Use at your own risk.
#
# Source: https://angelblanco.dev/blog/install-node-24-on-ubuntu-24
#
# Usage:
# curl -fsSL https://angelblanco.dev/scripts/ubuntu-install-node-24.sh | bash
#
# This file set up installation of Node JS and several package managers.
# Normally you will call it from your non-root user, elevated permisson
# will be granted with sudo.
#
set -e
# Basic confirmation module before executing the script.
confirm_action() {
read -p "$1 (y/n): " choice < /dev/tty
case "$choice" in
[Yy]|[Yy][Ee][Ss])
return 0
;;
[Nn]|[Nn][Oo])
return 1
;;
*)
echo "Invalid choice. Please enter 'y' or 'n'."
confirm_action "$1"
;;
esac
}
# You can configure this variables if needed
NODE_VERSION=24
NPM_PREFIX="~/.npm-global"
DEPS="ca-certificates curl gnupg"
TMP_DIR=$(mktemp -d)
echo "This script will install Node.js and optionally other package managers."
echo ""
if ! confirm_action "Install Node.js version $NODE_VERSION?"; then
echo "Skipping Node.js installation. Exiting."
exit 0
fi
echo "Installing deps needed for installing nodejs..."
sudo apt update
sudo apt install -y $DEPS
echo "Installing nodejs"
curl -fsSL https://deb.nodesource.com/setup_$NODE_VERSION.x -o $TMP_DIR/nodesource_setup.sh
sudo -E bash $TMP_DIR/nodesource_setup.sh
sudo apt-get install -y nodejs
mkdir -p ~/.npm-global
npm config set prefix $NPM_PREFIX
echo "Npm prefix set to $NPM_PREFIX"
echo "Node.js installation completed."
echo "Node version: "
node --version
echo ""
if confirm_action "Enable Yarn and pnpm via corepack?"; then
echo "Enabling corepack..."
sudo corepack enable
echo "Corepack enabled."
echo "Yarn version: "
yarn --version
echo "PNPM version: "
pnpm --version
fi
echo ""
if confirm_action "Install Bun?"; then
echo "Installing Bun..."
curl -fsSL https://bun.sh/install | bash
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
echo "Bun version: "
bun --version
fi
echo ""
echo "Installation process finished."
echo ""
echo "You probably want to add global npm bin directory to your path on your .bashrc or .zshrc, to do so, include this line"
echo 'export PATH=~/.npm-global/bin:$PATH'
echo ""
Node Version Manager (NVM) is a fantastic tool for managing multiple Node.js versions. However, I personally prefer to stick to a single, system-wide installation of the latest LTS version. This approach forces me to keep my projects updated. Besides, Node.js rarely introduces major breaking changes in its LTS releases, so the upgrade process is usually straightforward.
If you prefer the flexibility of NVM, you can still use it, but you would likely choose one method or the other. After installing NVM, you would manage your package managers like yarn
and pnpm
by installing them globally via npm
for each Node version you use. You could then use aliases to switch between different versions of your tools. Be aware that this can sometimes lead to path conflicts or unexpected behavior, so be mindful of which versions are active in your shell.