Back to blog
GuidesSeptember 15, 2026ยท3 min read

How to Install npm on Ubuntu

How to Install npm on Ubuntu

How to Install npm on Ubuntu

The best way to install npm on Ubuntu is via nvm: follow the instructions for nvm installation and run nvm install --lts. In this guide, we explain how to install npm using nvm, why the apt alternative is usually a bad idea and why nvm does not need sudo when doing global installs while apt-installed npm does.

How do I install npm on Ubuntu with nvm?

Just install nvm with its official install script, then run nvm install --lts. npm is packaged together with Node.js, so you don't need to install it separately.

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

This is the exact install script and command from nvm's own documentation, which explains that nvm is "a version manager for node.js, designed to be installed per-user, and invoked per-shell" โ€” and that per-user, per-shell nature is the reason the other parts of this guide talk about sudo and per-project versions.

Can I just install npm with apt instead?

It's possible to do with sudo apt install nodejs npm, but Ubuntu's default repositories contain only an outdated, end-of-support Node.js version.

$ sudo apt update
$ sudo apt install nodejs npm

One widely used Ubuntu Node.js guide explains it directly: "Ubuntu maintains its package builds through the Ubuntu security update process, but the upstream Node.js 18 release line is end-of-life" โ€” in other words, the apt version continues receiving security updates but is not able to receive new feature releases and run packages which require a more recent Node.js.

Why doesn't npm need sudo when installed with nvm?

nvm installs Node.js and npm into your own home directory entirely, per user. As nothing is installed into system directories, using npm -g for installing a package globally does not require elevated permissions.

$ npm install -g some-package

nvm's documentation confirms this directly: "you do not need sudo to globally install a module with npm -g" โ€” unlike apt-installed npm, where npm -g writes to system directories which are owned by root and thus require sudo.

How do I check my installed npm and Node.js versions?

Just use node -v and npm -v โ€” both commands output only the version number.

$ node -v
$ npm -v

This is precisely the pair of commands which nvm's own documentation suggests as a check for a working installation โ€” running nvm install --lts and those two commands right afterwards will be enough to make sure that you have installed the version you wanted.

How do I switch Node.js versions for different projects?

Create an .nvmrc file containing the required Node.js version in each project's directory. nvm will read that file automatically and switch to the specified version, allowing to use a different Node.js version in each project.

$ echo "20" > .nvmrc
$ nvm use

This project-specific functionality is exactly what .nvmrc files are meant for according to nvm's documentation โ€” which is impossible when having a single system-wide npm installed via apt, as that version would be shared between all projects on the machine.

Our VPS plans and Bare Metal servers come with a full Ubuntu shell environment to run nvm from, so managing Node.js versions per project will work exactly like described above.

Get started with Orbit Servers

Low-latency VPS, bare metal, and colocation across the US, EU, and APAC - provisioned instantly and built for performance-critical workloads.

Get started
J

Written by

Julius

Related posts