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 became LTS on October 28, 2025 and is supported until April 2028. For a new setup, install Node.js 26 on Ubuntu 26.04 instead. 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.
The easy way
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 don't have curl installed:
sudo apt update
sudo apt install curl
The step-by-step guide
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.
1. Update dependencies and add the NodeSource repository
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 -
2. Install Node.js and npm
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.
3. Configure npm's global prefix
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
4. Enable Corepack (for Yarn and pnpm)
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.
5. Install Bun (optional)
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, which needs unzip:
sudo apt install -y unzip
curl -fsSL https://bun.sh/install | bash
The script
This is the complete script that automates the steps above. It asks for confirmation before each step and removes its temporary files on exit.
#!/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 script installs Node.js and several package managers.
# Run it as your non-root user: it asks for elevated permissions
# with sudo when needed.
#
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 these variables if needed
NODE_VERSION=24
NPM_PREFIX="~/.npm-global"
DEPS="ca-certificates curl gnupg"
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
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 the dependencies needed to install Node.js..."
sudo apt update
sudo apt install -y $DEPS
echo "Installing Node.js..."
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..."
sudo apt install -y unzip
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 "Add the global npm bin directory to your PATH by adding this line to your .bashrc or .zshrc:"
echo 'export PATH=~/.npm-global/bin:$PATH'
echo ""
What about NVM?
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.