Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
VGSources
Blog

How to Install Node.js on Ubuntu (nvm, apt, and NodeSource)

A complete Ubuntu guide to installing Node.js and npm. Learn when to use nvm, apt, or NodeSource, install LTS or a specific version, verify PATHs, fix permissions and shell issues, and remove conflicting installations safely.
Length13 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For most Ubuntu developers, install Node.js with nvm (Node Version Manager). It installs Node.js and npm for your user, lets different projects use different versions, and avoids the global npm permission problems that often follow system installers. The commands below work inside Ubuntu Desktop, Ubuntu Server, virtual machines, cloud VPSs, and Ubuntu under WSL. If you need one system-wide runtime for a daemon, use Ubuntu’s apt packages or a carefully managed NodeSource package instead.

Node.js runs JavaScript outside a browser. npm is the package manager and command-line interface normally used with it to install project dependencies and JavaScript tools. npm’s installation guidance recommends a Node version manager for most users: npm installation documentation.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the installation method first

Ubuntu offers several legitimate ways to install Node.js. They are not interchangeable: each puts files in different locations, follows a different upgrade process, and behaves differently for services and other users. Pick one primary method before running commands.

Method Best for Main advantage Main drawback
nvm Developers, learners, and machines running several projects Per-user installation with simple version switching Node is available to the configured user and shell; system services do not automatically inherit it
Ubuntu apt A simple, system-managed installation Native Ubuntu packaging, updates, auditing, and removal The repository version depends on your Ubuntu release and may be older than the current Node.js LTS
NodeSource repository Administrators who want a newer system-wide Debian package apt integration with newer Node.js lines than some Ubuntu repositories Adds a third-party repository and can conflict with existing Node.js installations
Official Node.js binary Controlled deployments with a deliberate filesystem layout First-party prebuilt binary You must manage extraction, PATH configuration, upgrades, and removal yourself

For production services, choose the method that matches how the service starts. An nvm installation belongs to one user and is normally loaded by that user’s shell profile; a system-wide package is often easier for systemd, cron, CI runners, and containers. Do not install the same release with apt, nvm, and another repository without checking which executable your PATH selects.

What Ubuntu versions and environments do these commands cover?

The examples target currently supported Ubuntu releases and ordinary Ubuntu-based environments. Ubuntu’s package manager is apt; apt update refreshes the local package index and apt install installs packages, as described in Ubuntu’s package-management documentation. Historical Ubuntu releases can have different repositories, OpenSSL libraries, shell defaults, or support status, so check your release before troubleshooting a package failure.

The same commands run in:

  • Ubuntu Desktop terminals
  • Ubuntu Server over SSH
  • Ubuntu virtual machines and cloud VPSs
  • Ubuntu installed under Windows Subsystem for Linux (run them inside the Ubuntu distribution, not in Windows PowerShell)

You need an account with administrative privileges for commands prefixed with sudo. nvm itself should normally be installed as your regular user, not as root.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended method: install Node.js with nvm

nvm keeps Node.js versions under your home directory. You can install an LTS release for ordinary work, test another major release, and switch back without replacing a system package. The current official Node.js download page shows this approach for Linux: Node.js downloads.

1. Install the prerequisite

sudo apt update
sudo apt install -y curl

sudo apt update refreshes Ubuntu’s package indexes. sudo apt install -y curl installs the command-line downloader used by the nvm installer. These are the only privileged steps in the nvm path.

2. Install nvm for your user

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

The installer shown above is version v0.40.6, the version displayed in the current Node.js instructions at the time of writing. Installer versions can change, so compare the command with the current Node.js download page and the nvm project documentation when you install later.

Piping a downloaded script directly to a shell is convenient but gives you no opportunity to read it first. If you prefer to inspect it, download it, review it, then execute and remove the temporary file:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -o install_nvm.sh https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh
less install_nvm.sh
bash install_nvm.sh
rm install_nvm.sh

Reading the script lets you see what will execute; it is not, by itself, proof that the script is safe. Do not run the nvm installer through sudo or install it into root’s home directory unless you intentionally need a separate root-only setup.

3. Load nvm into the current shell

The installer adds shell initialization to a profile file. Bash users normally run:

source ~/.bashrc

If your login shell is Zsh, load its profile instead:

source ~/.zshrc

Closing and reopening the terminal has the same effect. Profile loading varies between interactive shells, login shells, noninteractive jobs, and WSL terminal sessions, so a new terminal is a useful first check.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Verify that nvm loaded

command -v nvm

The expected output is nvm. Use command -v, not which nvm: nvm is implemented as a sourced shell function rather than a normal executable file. The nvm documentation explains this distinction at github.com/nvm-sh/nvm.

5. Install the latest LTS release

nvm install --lts
nvm use --lts

nvm install --lts downloads the current long-term-support line and activates it when installation completes. nvm use --lts explicitly selects that line in the current shell. LTS is the sensible default for most applications because it prioritizes a long maintenance window and ecosystem compatibility. The exact version printed is intentionally not fixed: releases change over time.

For a date-stamped reference, the official download page identified Node.js v24.19.0 as the latest LTS and v26.7.0 as the latest Current release on August 18, 2026. Those numbers are not a permanent requirement and should not be copied into an evergreen command.

6. Make LTS the default in new shells

nvm alias default 'lts/*'

The alias tells nvm which installed LTS line to select when a new shell starts. You can still switch to another installed version for a particular project.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

7. Verify both Node.js and npm

node -v
npm -v

Both commands should print version strings. The values depend on the release available when you run the command and on the npm version bundled with that Node.js distribution. Installing Node.js normally includes npm, but package versions can differ between nvm, Ubuntu, and third-party packages.

8. Run a minimal runtime check

node -e "console.log('Node.js is working')"

If the command prints Node.js is working, the interpreter can start and execute JavaScript without creating a project.

Install and switch to a specific Node.js version

Projects sometimes require a particular major release or exact patch version. nvm can keep several versions installed at once.

Install a major release

nvm install 24
nvm use 24

This installs the newest available release in the 24.x line and selects it for the current shell. A major-version request is preferable when a project supports a release line but should receive compatible patch updates.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install an exact release

nvm install 24.19.0
nvm use 24.19.0

An exact version is useful when a lockfile, deployment image, or compatibility test requires a reproducible runtime. Confirm that the requested release is still available before relying on it for a new machine.

List versions

nvm ls
nvm ls-remote

nvm ls shows versions installed locally. nvm ls-remote queries versions available for download. The remote list can be long; use it to confirm a version rather than guessing a release number.

Set a major version as the default

nvm alias default 24

New shells will select the installed 24.x version until you change the alias. A project-specific selection should normally live in a project file rather than changing your global default.

Use a project’s .nvmrc file

echo "24" > .nvmrc
nvm install
nvm use

Run these commands from the project directory. The file records the requested version, while nvm install obtains it if necessary and nvm use activates it. Commit .nvmrc when the team agrees on a runtime; each developer still needs nvm installed.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install Node.js from Ubuntu’s apt repository

Use Ubuntu’s own packages when one system-wide version is enough and integration with Ubuntu updates matters more than receiving the newest Node.js line immediately.

sudo apt update
sudo apt install -y nodejs npm

Check what was installed:

node -v
npm -v
apt policy nodejs

apt policy nodejs displays the installed version, the candidate version, and the repositories supplying it. The candidate depends on your Ubuntu release and enabled sources, so this method may provide an older major line than the current Node.js LTS. Do not assume a tutorial’s fixed version number applies to your machine.

apt is a good fit when:

  • A single system-wide runtime is sufficient.
  • An application is maintained as an Ubuntu package or service.
  • You want upgrades and removal handled entirely through Ubuntu’s package database.
  • The application’s documented minimum Node.js version is satisfied by the candidate shown by apt policy.

Do not install Ubuntu’s nodejs package and then add nvm without checking PATH precedence. Both installations can remain present, but users may run one version while a service runs another.

Install a newer system-wide package with NodeSource

NodeSource is a separate package distributor and apt repository, not the Node.js project itself. Its Debian and Ubuntu instructions add a repository and then install a nodejs package. This is appropriate when an administrator needs a newer system-wide package and accepts the additional repository trust and maintenance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the current LTS channel

sudo apt update
sudo apt install -y curl
curl -fsSL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt install -y nodejs
node -v
npm -v
rm nodesource_setup.sh

The setup_lts.x endpoint tracks the current LTS channel rather than hard-coding an obsolete major number. The setup script changes apt’s repository configuration; review the current support information at NodeSource’s distribution documentation before using it on a new Ubuntu release.

Use the Current channel only deliberately

curl -fsSL https://deb.nodesource.com/setup_current.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt install -y nodejs
node -v
npm -v
rm nodesource_setup.sh

Current contains the newest Node.js features and is useful for testing or a project that explicitly requires it. Prefer the LTS channel for most production deployments. The repository setup script is not equivalent to Ubuntu’s own package source, and packages from different sources can conflict with one another.

Before switching an existing machine to NodeSource, identify installed packages and active paths. Keep one deliberate system-wide source where possible. Do not add the repository solely because Ubuntu’s version looks old; first check the application’s actual engine requirement.

Manual official binaries and Snap: when they make sense

The official Node.js site also publishes prebuilt Linux binaries. A controlled deployment may download and extract one into a chosen directory, but you must define PATH entries, select ownership and permissions, schedule upgrades, and remove old files yourself. That work makes manual extraction a poor beginner path.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Snap can work for some Ubuntu setups, but its channel, confinement, and command behavior need to be checked against your deployment. It is not the central recommendation here because nvm and apt make version selection and system administration more explicit for the audiences covered by this guide.

Confirm which Node.js installation is active

When a machine has ever used apt, nvm, a third-party repository, Snap, or a manually extracted binary, verify the path before changing anything:

node -v
npm -v
command -v node
command -v npm
type -a node
type -a npm

Typical paths provide clues:

  • /usr/bin/node is commonly an apt-managed executable.
  • A path under ~/.nvm/versions/node/ indicates an nvm-managed version.
  • Another directory may indicate a manual binary, Snap command, or third-party package.

For nvm, also run:

nvm current
nvm ls

If command -v node still points to a system binary after nvm use, inspect shell initialization and PATH ordering before uninstalling anything. A system service may intentionally use the system binary even while your interactive terminal uses nvm.

Test npm with a small project

After the version checks, create a throwaway project to confirm that npm can write a project directory and that Node.js can run the resulting file:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
mkdir node-test
cd node-test
npm init -y
printf "console.log('npm project works')n" > index.js
node index.js

The expected output is npm project works. The test uses a local project and does not need administrative privileges. Do not use sudo npm install as a test or as a normal development workflow.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common installation problems

nvm: command not found

Reload the profile that matches your shell:

source ~/.bashrc
# or
source ~/.zshrc
command -v nvm

If it is still unavailable, close and reopen the terminal. Then inspect the nvm project’s shell-setup instructions at github.com/nvm-sh/nvm instead of repeatedly running the installer. The installer may have updated a different profile from the one your terminal reads.

node: command not found after nvm installation

First verify that nvm itself loaded:

command -v nvm

If it prints nvm, install and activate a Node.js release:

nvm install --lts
nvm use --lts
nvm current
command -v node

If nvm is missing too, fix shell initialization before diagnosing Node.js.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

npm reports permission errors

The common trigger is a system-installed npm combined with a command such as:

sudo npm install -g some-package

With nvm, select the managed version and install global tools as your user:

nvm use --lts
npm install -g some-package

npm documents version managers as a way to avoid the ownership and permissions problems associated with installer-based global package locations: npm’s installation guidance. A package that truly belongs to a system image should instead be managed by that image’s package or deployment process, not by repeatedly mixing root and user-owned npm directories.

Several installations are colliding

Do not purge packages before identifying the one you intend to keep. Collect paths and versions:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
command -v node
command -v npm
type -a node
type -a npm
node -v
npm -v
nvm ls

Choose a single workflow for the user or service, then adjust PATH and shell initialization. Removing an apt package can break a system service that depends on it, even if your terminal works with nvm.

The Ubuntu package is older than expected

Inspect the candidate and its source:

apt policy nodejs

Then choose deliberately: keep apt for stability, use nvm for a newer user-managed runtime, or use NodeSource for a newer system-wide package. An older number is not automatically a problem if the application supports it.

npm does not support the installed Node.js version

Select a compatible version already installed:

nvm ls
nvm use <working-version>

If the installed release is broken, nvm documents removing it and reinstalling with a compatible npm option:

nvm uninstall <broken-version>
nvm install --latest-npm <version>

Replace the angle-bracket values with real versions; do not type the brackets literally.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A native npm module fails to compile

Some packages include C/C++ or other native code. Node.js installation alone does not install every compiler and header they might need. If the package’s documentation requires standard Ubuntu build tools, add them conditionally:

sudo apt update
sudo apt install -y build-essential

Install only the dependencies required by the failing package and read its error output; build tools do not fix an incorrect Node.js version or a missing system library by themselves.

Node.js works in a terminal but not in systemd, cron, or CI

This is expected when a service relies on nvm but does not read your interactive shell profile. Noninteractive processes may never define NVM_DIR or prepend the nvm-managed binary directory to PATH.

  • Use a system-wide apt or NodeSource installation for the service.
  • Configure the service with the absolute path returned by command -v node for the intended runtime.
  • Use a deployment mechanism that explicitly initializes nvm before launching the process.
  • Do not assume that a successful command in your SSH shell proves the daemon sees the same executable.

The installer was run as root

nvm is intended for an individual user. Avoid commands such as:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo bash -c 'curl ... | bash'

Install only Ubuntu prerequisites with sudo, then run the nvm installer as the user who will run Node.js. If root already has an nvm installation, it does not automatically serve other users or services.

Uninstall Node.js safely

Identify the active installation before removing it. The removal command depends on the method and can affect other applications.

Remove an nvm-managed version

nvm ls
nvm uninstall <version>

Replace <version> with the exact entry shown by nvm ls. Uninstalling one version leaves other nvm versions and your project files intact. To remove nvm itself, follow the shell-profile cleanup instructions in the nvm documentation; removing a directory without removing its profile lines can leave confusing startup errors.

Remove Ubuntu’s apt packages

sudo apt remove nodejs npm

This removes the packages while leaving configuration files that apt may preserve. Check what depends on them first, especially on a server. Do not remove a system package merely because nvm is also installed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Remove a NodeSource installation

NodeSource’s repository documentation describes purging the nodejs package and removing its apt source and keyring files: NodeSource distributions documentation. Follow the instructions for the exact repository configuration on your machine. Inspect the files and sources before deleting them; a blanket removal command can affect other packages that use the same repository or keyring.

Operational checklist

  • Choose nvm for most per-user development and multi-project work.
  • Choose apt for a simple Ubuntu-managed system-wide runtime when its candidate version meets your application’s requirement.
  • Choose NodeSource when you deliberately need a newer system-wide Debian package and accept a third-party repository.
  • Use LTS unless you have a concrete reason to test or run the Current line.
  • Verify node -v, npm -v, and the executable paths after every installation or change.
  • Keep production services independent of an interactive .bashrc unless their startup explicitly initializes nvm.
  • Avoid mixing installation methods without documenting which path each user and service should use.

The Bottom Line

For an Ubuntu development workstation, install nvm as your regular user, run nvm install --lts, set the default alias, and verify the resulting node and npm paths. Use apt or NodeSource instead when a system service needs one centrally managed runtime.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.