
September 09, 2026
12 min read
By Kokil Thapa | Last reviewed: September 2026
You need to install Node.js on Ubuntu before you can build front-end assets, run JavaScript tooling, or deploy modern web stacks. Ubuntu's default packages often lag behind current releases. That mismatch breaks Vite 8.x builds and npm 12 workflows on real projects. This guide covers the two methods I actually use in production: NodeSource for servers and nvm for development machines. It also shows how to verify versions, pick the right LTS line, and avoid the mistakes I see on Ubuntu server setup jobs.
nvm install --lts on dev machines. Both methods deliver current npm 12 and avoid outdated distro packages.What is the best way to install Node.js on Ubuntu?
The best method depends on whether the machine is a production server or a developer workstation. They have different priorities. Servers need one pinned version, predictable upgrades, and no per-user path tricks. Dev laptops need multiple Node versions for different client repos.
On production Ubuntu 22.04 or 24.04 VPS instances, I use the official NodeSource setup script to install Node.js 26 LTS. Node 26 is the current LTS line in 2026. Node 24 LTS remains supported until April 2028 if you need a conservative choice. I avoid the default apt install nodejs package on servers. It often ships an old major version that conflicts with modern tooling.
On local dev machines, nvm (Node Version Manager) is the practical default. You can switch between Node 20, 22, and 26 per project. I have used this pattern across Laravel apps where Vite 8.x and legacy webpack builds coexist. For background on runtime trade-offs, see the Bun vs Node vs Deno comparison.
Before installing anything, update your base system. Stale packages cause GPG key and dependency errors during setup. Run the standard refresh first:
sudo apt update && sudo apt upgrade -y
sudo apt install -y curl ca-certificates gnupg build-essential The build-essential package matters. Some native npm modules compile C++ bindings during install. Missing compilers produce cryptic node-gyp errors. I hit this regularly on fresh VPS images during Ubuntu server setup for PHP apps.
How do you install Node.js on Ubuntu using NodeSource?
NodeSource provides maintained apt repositories for current Node.js releases. This is my default on Ubuntu web servers that build front-end assets during CI or deploy. The process takes about two minutes on a clean 24.04 instance.
Step 1: Add the NodeSource repository
Download and run the setup script for Node.js 26.x. Always verify the script URL against the Node.js download page before piping to bash. This is standard practice on any production box.
curl -fsSL https://deb.nodesource.com/setup_26.x | sudo -E bash - The script detects your Ubuntu version, imports the signing key, and writes an apt source list entry. If you prefer Node 24 LTS, replace setup_26.x with setup_24.x. Check the Node.js release schedule before picking a line.
Step 2: Install Node.js and npm
sudo apt install -y nodejs This installs both node and npm. Confirm the versions immediately:
node -v
npm -v Expected output in 2026: v26.x.x for Node and 10.x or higher for npm. npm 12 ships with current Node releases. If npm looks wrong, run sudo npm install -g npm@12 to align it.
Step 3: Configure npm global paths on servers
Never run sudo npm install -g for application packages on a shared server. It creates root-owned files and permission headaches. Set a user-level global directory instead:
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc On deploy servers where Node only builds assets, you may skip global tools entirely. Install devDependencies locally inside each release directory. That matches the pattern in my CI/CD caching for Composer and npm installs guide.
How do you install Node.js on Ubuntu with nvm?
nvm installs Node in your home directory. No sudo is required for version switches. This is ideal when you juggle Laravel 12 and Laravel 13 projects with different engine requirements. The tool lives on GitHub at nvm-sh/nvm.
Step 1: Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
source ~/.bashrc
nvm --version If the shell reports command not found, confirm the installer appended its block to ~/.bashrc or ~/.zshrc. Open a new terminal session and retry.
Step 2: Install Node.js LTS
nvm install --lts
nvm use --lts
nvm alias default lts/* Install a specific version when a project pins one in .nvmrc:
echo "26" > .nvmrc
nvm install
nvm use Run nvm ls to see all installed versions. Run nvm use 24 to switch instantly. This beats reinstalling system packages every time a client repo demands a different major.
Step 3: Keep nvm out of production cron paths
A common production bug: cron jobs reference /usr/bin/node while nvm puts binaries under ~/.nvm/versions/node/. Scheduled tasks silently fail. On servers, use NodeSource instead. Reserve nvm for laptops and local VMs. I learned this during deploy troubleshooting on sites that share a Linux system administration pipeline.
How do you verify and manage Node.js after installation on Ubuntu?
Installation is only half the job. You need repeatable checks and a sane upgrade path. Skipping verification is how broken builds reach production.
Run a basic health check
- Confirm Node and npm versions:
node -v && npm -v - Confirm binary location:
which node && which npm - Run a one-liner:
node -e "console.log(process.version)" - Test npm registry access:
npm ping - Install a throwaway package locally:
npm install chalk --no-save && rm -rf node_modules
If npm ping fails, check DNS and outbound firewall rules. Ubuntu servers with strict UFW policies sometimes block HTTPS to the registry. See the UFW firewall guide if that applies.
Upgrade Node.js safely
On NodeSource systems, re-run the setup script for the new major line. Then run sudo apt update && sudo apt install --only-upgrade nodejs. Test your build pipeline before touching production. A Vite major bump can break older config files.
On nvm systems, run nvm install 26 && nvm alias default 26. Rebuild native modules after any major upgrade:
npm rebuild
npm run build For JSON config checks during debugging, the JSON formatter tool helps validate package.json and lockfile snippets quickly.
Pair Node with the rest of your stack
Most of my Ubuntu web servers run PHP-FPM and MySQL alongside Node. Node builds assets; PHP serves the app. After installing Node, confirm your full chain still works. Install PHP via the PHP on Ubuntu guide. Install MySQL via the MySQL on Ubuntu guide. Then deploy Laravel with the Laravel on Ubuntu VPS with Nginx walkthrough.
| Method | Best for | Node version | Sudo required | Multi-version |
|---|---|---|---|---|
| NodeSource apt | Production VPS, CI runners | Current LTS (26.x) | Yes (install only) | No |
| nvm | Developer laptops, local VMs | Any release line | No | Yes |
| Ubuntu default apt | Quick tests only | Often outdated | Yes | No |
| Manual binary tarball | Air-gapped or custom paths | Your choice | Yes (system path) | No |
The table matches what I recommend to clients choosing a stack. For a full LEMP setup that includes asset builds, follow the LEMP stack on Ubuntu guide. Repository hygiene matters too. Read the Ubuntu repository management guide if you maintain custom apt sources.
Which Node.js installation method should you use on Ubuntu servers?
Pick your method before you install anything else. Changing later wastes time and breaks cron paths. Here is the decision logic I use on real deployments.
Choose NodeSource when
- The machine is a production or staging VPS
- CI/CD pipelines SSH in and run
npm ci && npm run build - You want one LTS version managed through apt
- Cron or systemd units call
/usr/bin/nodedirectly - The server also runs PHP, MySQL, and Nginx for a Laravel or Symfony app
On projects like Adventure Third Pole Trek, Laravel and Livewire handle the app. Node only compiles front-end assets during deploy. NodeSource keeps that pipeline boring and predictable.
Choose nvm when
- You are on a developer laptop or local Docker-free VM
- Different repos require Node 20, 22, or 26
- You test upgrades without touching system packages
- No cron jobs depend on a fixed system binary path
Avoid these mistakes
Mixing nvm and NodeSource on the same server creates path confusion. which node may point to nvm in your shell but /usr/bin/node in cron. Pick one method per machine.
Installing Node as root and running sudo npm install -g pm2 scatters root-owned files under /usr/lib/node_modules. Use a deploy user with NodeSource, or configure the npm prefix as shown above.
Skipping npm ci in favour of npm install on deploy servers produces inconsistent lockfiles. Commit your lockfile. Build from it. This aligns with zero-downtime Deployer workflows I run on legal-tech and eCommerce sites.
Running Node as a public-facing app server alongside Apache on port 80 without a reverse proxy is a security risk. For PHP apps, let Nginx proxy to PHP-FPM. Use Node only for build steps unless you deliberately run a Node API behind a proxy.
Security hardening still applies after Node is installed. Keep the server patched via the Ubuntu security updates guide. Apply broader hardening from server hardening for Ubuntu web servers. If you containerise later, the Docker on Ubuntu guide covers an alternate path where Node lives inside images instead.
For WooCommerce or Shopify theme work, Node builds SCSS and JS locally. The production server may never need Node at all. Commit compiled assets instead. That is the workflow on Petals Qatar and similar eCommerce projects. When the server does need Node, NodeSource is the right call.
Need help wiring Node into a full deploy pipeline? The web development services page covers Laravel, eCommerce, and VPS setup end to end. For ongoing patches and monitoring, see support and maintenance.
Key Takeaways
- Use NodeSource to install Node.js 26 LTS on Ubuntu production servers; use nvm on dev machines.
- Install
build-essentialbefore npm so native modules compile without node-gyp errors. - Verify with
node -v,npm -v, andwhich node— then runnpm pingto test registry access. - Never mix nvm and NodeSource on one server; cron will call the wrong binary path.
- On PHP/Laravel stacks, Node builds assets; Nginx and PHP-FPM serve the application in production.
- Commit lockfiles and run
npm ciin deploy scripts for reproducible builds.
People Also Ask
Does Ubuntu 24.04 come with Node.js preinstalled?
No. Ubuntu 24.04 does not ship Node.js in the default minimal install. You must add it manually via NodeSource, nvm, or apt. The default apt version, when available, is usually too old for Vite 8.x and npm 12 workflows.
Should I use Node.js 26 or Node.js 24 LTS on Ubuntu in 2026?
Choose Node.js 26 LTS for new projects in 2026. It is the current LTS line with active support. Pick Node 24 LTS only if a dependency or hosting policy explicitly requires it. Node 24 remains supported until April 2028.
Can I install Node.js on Ubuntu without sudo?
Yes. nvm installs Node entirely under your home directory. No root access is needed after the initial nvm installer runs. This makes nvm the standard choice on shared dev machines and corporate laptops with restricted sudo.
Do I need Node.js on my Ubuntu server if I run Laravel?
You need Node during the build step to compile Vite or Mix assets. You do not need Node running as a daemon in production for a standard Laravel app. Many teams build assets in CI and deploy only the compiled files to the VPS.
Get your Ubuntu build pipeline working
Install Node.js on Ubuntu with the right method for each machine. NodeSource for servers, nvm for local work, and a verification checklist before your first deploy. That combination prevents the version mismatches and cron path bugs I debug on production boxes every month. If you want help setting up a full Ubuntu VPS with PHP, MySQL, Node, and automated deploys, contact us or review the essential Ubuntu terminal commands reference to sharpen your day-to-day workflow.
Frequently Asked Questions
0 Comments
Leave a comment
Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

