Node.js lets you run JavaScript on the server, and it powers everything from small APIs to full frameworks like Next.js, NestJS, and Express. Installing it on Ubuntu 24.04 sounds trivial, but there are several ways to do it, and they are not equal: the wrong choice leaves you stuck on an outdated runtime or fighting version conflicts months later. This guide walks you through all three reliable methods, compares them honestly, and recommends the right one for your situation. By the end, you will have a current Node.js LTS running, npm working, and a smoke test proving your setup is solid.
This guide is for developers, DevOps engineers, and anyone managing an Ubuntu 24.04 server (VPS, bare metal, or WSL2) who needs Node.js for a real project.
Prerequisites
- An Ubuntu 24.04 LTS system (22.04 commands are identical unless noted) with sudo access.
- A working internet connection.
- Basic familiarity with the Linux terminal.
- About 10 minutes of your time.
Which Node.js version should you install?
As of October 2026, Node.js 24 is the active LTS (long-term support) release, supported through April 2028. Node.js 26 becomes LTS later in October 2026, but Node.js 24 remains the safest default for production today. Avoid installing whatever old version a repository happens to ship — an unsupported Node (like Node.js 20, which reached end of life in April 2026) leaves your apps exposed to unpatched vulnerabilities.
Method 1: NodeSource APT repository (recommended for production)
NodeSource maintains official Debian/Ubuntu packages for current Node.js releases. This installs Node.js system-wide through apt, so updates arrive with your normal apt upgrade cycle. This is the best choice for servers and production deployments.
Step 1: Update your package index and install curl
sudo apt update
sudo apt install -y curl
This refreshes your package list and makes sure curl is available to download the NodeSource setup script.
Step 2: Download and run the NodeSource setup script
curl -fsSL https://deb.nodesource.com/setup_24.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
The first command downloads the setup script for the Node.js 24.x line. The second runs it with sudo, preserving your environment (-E); it adds NodeSource's signed repository and GPG key to your system and refreshes the package index.
Step 3: Install Node.js
sudo apt install -y nodejs
The nodejs package from NodeSource includes both the node binary and npm, so you do not need to install npm separately.
Step 4: Verify the installation
node -v
npm -v
You should see something like v24.x.x and 11.x.x. If both commands print versions, NodeSource installation succeeded.
Method 2: NVM — Node Version Manager (best for developers)
NVM installs Node.js inside your home directory instead of system-wide. You can install, switch between, and remove multiple Node versions with a single command. This is ideal for development machines and for teams that maintain projects on different Node lines.
Step 1: Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh | bash
This downloads the official NVM install script (v0.40.8, current at the time of writing) and runs it. It clones NVM into ~/.nvm and adds the sourcing lines to your ~/.bashrc. Check the NVM releases page if you want the very latest tag.
Step 2: Load NVM into your current shell
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
The install script updates your shell config, but those changes only apply to new terminals. These two lines load NVM immediately so you can use it right away.
Step 3: Install the Node.js LTS release
nvm install --lts
NVM downloads, compiles-free binary install of the latest LTS (Node.js 24) into ~/.nvm/versions/node. Add --latest-npm if you also want the newest npm bundled with it.
Step 4: Verify and set a default
node -v
npm -v
nvm alias default lts/*
The first two commands confirm versions. The third sets the LTS line as your default so every new shell uses it. List everything you have with nvm ls and switch with nvm use 24.
Method 3: Ubuntu's default repositories (fast but outdated)
Ubuntu ships its own nodejs package. One command and you are done — but the version is frozen at whatever Ubuntu packaged for 24.04, which lags the current LTS by a long way.
Step 1: Install from Ubuntu's repositories
sudo apt update
sudo apt install -y nodejs npm
This installs Node.js and npm from Ubuntu's universe repository. It is the simplest method, and it needs no third-party repository.
Step 2: Check what you got
node -v
Expect a much older version than the NodeSource or NVM methods produce. That is the trade-off of this method.
Which method should you pick?
- Production server or single-version VPS: Method 1 (NodeSource). System-wide install, current LTS, updated through apt.
- Development machine or multi-version work: Method 2 (NVM). Switch versions per project, no sudo required, isolated in your home directory.
- Throwaway test or minimal container: Method 3 (Ubuntu apt). Fastest, but outdated — never ship real workloads on it.
Keeping Node.js updated
Node.js moves fast, and an install you never update slowly becomes a liability. With Method 1, updates flow through the normal system updater:
sudo apt update
sudo apt install --only-upgrade nodejs
This installs newer Node.js 24 patch and minor releases without touching anything else. Major upgrades (24 to 26) are different — always test your application against the new major in staging first, since V8 and dependency behavior can change.
With NVM, update with nvm install --lts --reinstall-packages-from=current: it fetches the newest LTS, migrates your global npm packages, and switches you over in one shot.
Verify it worked: run a real app
A version number is not proof. Write a tiny HTTP server and hit it:
Step 1: Create a test server
cat > server.js <<'EOF'
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Node.js is working on Ubuntu 24.04\n');
});
server.listen(3000, () => console.log('Listening on port 3000'));
EOF
This writes a minimal Node.js web server to server.js. The heredoc keeps quoting safe; the file is ready to run.
Step 2: Run it in the background and curl it
node server.js > server.log 2>&1 &
sleep 1
curl http://localhost:3000
You should see Node.js is working on Ubuntu 24.04. Kill the test server afterwards with pkill -f "node server.js". If curl prints your message, your Node.js install is genuinely functional, not just present.
Common issues and fixes
1. "node: command not found" after a NodeSource install
This usually means an older nodejs package is shadowing the new one, or the shell cached the old PATH lookup. Fix it with:
sudo apt remove -y nodejs npm
sudo apt install -y nodejs
hash -r
hash -r clears the shell's cached command locations so the next node lookup finds the fresh binary.
2. NVM says "nvm: command not found" in a new terminal
The install script writes sourcing lines to ~/.bashrc, but some terminals load ~/.profile instead. Open ~/.bashrc and confirm these lines exist at the end:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
If your terminal still does not load ~/.bashrc, add the same two lines to ~/.profile or ~/.zshrc.
3. npm install fails with EACCES permission errors
Never fix this with sudo npm. The root cause is usually a system-wide Node installed without proper prefix config. The clean fix: switch to NVM (Method 2), which installs everything under your home directory, or set npm's global prefix to a user-owned directory:
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
This redirects global installs away from root-owned paths and into your home directory.
4. NodeSource setup script fails with a GPG or 404 error
An old script cached locally, or an outdated OS release, causes this. Re-download the current script and make sure you are actually on a supported Ubuntu:
lsb_release -a
rm -f nodesource_setup.sh
curl -fsSL https://deb.nodesource.com/setup_24.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
lsb_release -a confirms your Ubuntu version; if it is not 22.04 or 24.04, the NodeSource repository may not have matching packages.
5. Two Node versions installed at once (apt + NVM conflict)
If you tried multiple methods, your shell may pick up the wrong node. Decide which one you want, remove the other (sudo apt purge nodejs for the apt one, or delete ~/.nvm for NVM), then open a fresh terminal and run which node to confirm exactly one binary remains.
Conclusion
You now have Node.js running on Ubuntu 24.04, installed the right way for your use case: NodeSource for servers, NVM for development, and a working smoke test to prove it. Keep your LTS current with regular apt upgrade (or nvm install --lts --reinstall-packages-from=current for NVM), and you will avoid the most common source of production surprises.
If you would rather not touch a terminal, XpertBees sets up and hardens production Node.js servers for clients every week — reach out and we will handle it end to end.

