Installing the latest version of node using nvm:

Install the latest nvm through its Github repo:

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

source ~/.bashrc

check the latest version of node and select it:

nvm list-remote

Out:

...
       v20.15.0   (LTS: Iron)
       v20.15.1   (LTS: Iron)
       v20.16.0   (Latest LTS: Iron)
        v21.0.0
        v21.1.0
        v21.2.0
        v21.3.0
        v21.4.0
        v21.5.0
        v21.6.0
        v21.6.1
        v21.6.2
        v21.7.0
        v21.7.1
        v21.7.2
        v21.7.3
        v22.0.0
        v22.1.0
        v22.2.0
        v22.3.0
        v22.4.0
        v22.4.1
        v22.5.0
        v22.5.1
        v22.6.0

Install the desired version of node:

nvm install v20.16.0
Answer from Benyamin Jafari on askubuntu.com
🌐
Node.js
nodejs.org › en › download
Node.js — Download Node.js®
Download a signed Node.js source tarball. Check out our nightly binaries or all previous releases or the unofficial binaries for other platforms. We are able to serve Node.js's downloads and maintain our infrastructure proudly due to the support of these partners, and more.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-install-node-js-on-ubuntu-20-04
How to Install Node.js on Ubuntu | DigitalOcean
May 2, 2025 - Learn how to install Node.js on Ubuntu using apt, NodeSource, and NVM. Choose the best method for your needs with this beginner-friendly guide
Discussions

What's the command to install Node on Ubuntu?
https://nodejs.org/en/download More on reddit.com
🌐 r/MeshCentral
10
0
May 12, 2025
Install Node.js on Ubuntu - Stack Overflow
I'm trying install Node.js on Ubuntu 12.10 (Quantal Quetzal), but the terminal shows me an error about lost packages. I tried with this: sudo apt-get install python-software-properties sudo add-apt- More on stackoverflow.com
🌐 stackoverflow.com
node.js - Install a specific nodejs version with apt-get - Stack Overflow
I am a newbie with Linux general, and here's what I am trying to achieve: I am trying to install nodejs version on Debian Linux with the following command: apt-get install nodejs=8.14.0 But I get... More on stackoverflow.com
🌐 stackoverflow.com
node.js - How to install a specific version of Node on Ubuntu/Debian? - Stack Overflow
I would like to install NodeJS version 0.8.18 on Ubuntu 12.04. I tried to install the newest version and then reverting to 0.8.18 by using nvm, but when I run my code apparently there is some problem More on stackoverflow.com
🌐 stackoverflow.com
🌐
Node.js
nodejs.org › en › download › archive › v25.2.1
Node.js® Download Archive
4 weeks ago - Download a signed Node.js v25.2.1 source tarball.
🌐
npm
docs.npmjs.com › downloading-and-installing-node-js-and-npm
Downloading and installing Node.js and npm | npm Docs
To publish and install packages to and from the public npm registry or a private npm registry, you must install Node.js and the npm command line interface using either a Node version manager or a Node installer. We strongly recommend using a Node version manager like nvm to install Node.js and npm.
🌐
Hostinger
hostinger.com › home › how to install node.js on ubuntu automatically and manually
How to install node.js on Ubuntu automatically and manually
July 22, 2025 - Update your Ubuntu’s repository to ensure you get the latest available version: ... Install Node.js from the local Ubuntu repository using this command.
Find elsewhere
🌐
Liquid Web
liquidweb.com › home › how to install node.js on ubuntu 22.04 via nvm
How to Install Node.js on Ubuntu 22.04 via NVM | Liquid Web
February 19, 2025 - Welcome to this comprehensive guide on installing Node.js on Ubuntu 22.04 via NVM (Node Version Manager).
🌐
Cherry Servers
cherryservers.com › home › blog › linux › how to install npm on ubuntu 24.04 (3 methods)
How to Install NPM on Ubuntu 24.04 (3 Methods) | Cherry Servers
March 26, 2025 - This guide explores three installation methods: using Ubuntu's default repository, the NodeSource repository, and the Node Version Manager (NVM). Each approach is suited to different use cases, such as stability, access to the latest features, or managing multiple Node.js versions.
🌐
Node.js
nodejs.org › en › download › package-manager › all
Node.js — Installing Node.js via package manager
October 15, 2025 - To install fnm, use this install script. fnm has cross-platform support (macOS, Windows, Linux) & all popular shells (Bash, Zsh, Fish, PowerShell, Windows Command Line Prompt). fnm is built with speed in mind and compatibility support for .node-version and .nvmrc files. The most recent release of Node.js is available via the www/node port.
Top answer
1 of 16
151

The n module worked for me.

Run this code to clear npm’s cache, install n, and install the latest stable version of Node:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

See: http://www.hostingadvice.com/how-to/update-node-js-latest-version/
And: https://www.npmjs.com/package/n

To install a specific version of node:

sudo n 18.17.1

To check what version:

node -v

You might need to restart

2 of 16
66

NVM (Node Version manager)

https://github.com/nvm-sh/nvm

Advantages:

  • allows you to use multiple versions of Node and without sudo

  • is analogous to Ruby RVM and Python Virtualenv, widely considered best practice in Ruby and Python communities

  • downloads a pre-compiled binary where possible, and if not it downloads the source and compiles one for you

Tested in Ubuntu 17.10:

curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.nvm/nvm.sh
nvm install 0.9.0
nvm install 0.9.9
nvm use 0.9.0
node --version
#v0.9.0
nvm use 0.9.9
node --version
#v0.9.9

For the particular case of the most recent long term support version (recommended if you can choose):

nvm install --lts
nvm use --lts
npm --version
npm install --global vaca
vaca

Since the sourcing has to be done for every new shell, the install script hacks adds some auto sourcing to the end of your .barshrc. That works, but I prefer to remove the auto-added one and add my own:

f="$HOME/.nvm/nvm.sh"
if [ -r "$f" ]; then
  . "$f" &>'/dev/null'
  nvm use --lts &>'/dev/null'
fi

With this setup, you get for example:

which node

gives:

/home/ciro/.nvm/versions/node/v0.9.0/bin/node

and:

which vaca

gives:

/home/ciro/.nvm/versions/node/v0.9.0/bin/vaca

and if we want to use the globally installed module:

npm link vaca
node -e 'console.log(require.resolve("vaca"))'

gives:

/home/ciro/.nvm/versions/node/v0.9.0/lib/node_modules/vaca/index.js

as mentioned at:

  • NodeJS require a global module/package
  • How do I import global modules in Node? I get "Error: Cannot find module <module>"?

so we see that everything is completely contained inside the specific node version.

For projects however, you are better off just using packages installed locally under node_modules and npx for executable to be able to have independent versions across projects, global usage is mostly for the Node executable itself and global CLI utilities not specific to any project.

Setting the NPM version

Simply:

npm install [email protected] -g

The executable is placed inside the current NVM version, so everything remains nice and isolated, e.g.:

which npm

gives something like:

/home/ciro/.nvm/versions/node/v14.17.0/bin/npm

How can I change the version of npm using nvm?

🌐
BlueVPS
bluevps.com › blog › how to install node.js on ubuntu 22.04: step-by-step guide
How to Install Node.js on Ubuntu 22.04: Step-by-Step Guide - Blog - BlueVPS
This method allows you to install Node.js using the official Ubuntu apt repository. Installing Node.js using the apt repository is a simple and easy method, but it will install the older Node.js version on your Ubuntu system.
🌐
Hostman
hostman.com › tutorials › how to install node.js and npm on ubuntu 24.04
How to Install Node.js and NPM on Ubuntu | Hostman
August 28, 2025 - Learn how to install Node.js and npm on Ubuntu machines, learning how to use NVM to install selected Node.js versions.
Price   $
Address   1999 Harrison St 1800 9079, 94612, Oakland
🌐
Microsoft Learn
learn.microsoft.com › en-us › windows › dev-environment › javascript › nodejs-on-wsl
Install Node.js on Windows Subsystem for Linux (WSL2)
See the WSL install documentation if you plan to use a Linux development environment with Node.js. These steps will include choosing a Linux distribution (Ubuntu is the default) and the version of Windows Subsystem for Linux (WSL 2 is the default and recommended version).
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-install-node-js-on-ubuntu-22-04
How to Install Node.js on Ubuntu (Step-by-Step Guide) | DigitalOcean
May 28, 2025 - In this guide, we will show you four different ways of getting Node.js installed on an Ubuntu server: using apt to install the nodejs package from Ubuntu’s d…
Top answer
1 of 4
90

I recommend using Node Version Manager:

NB: Node Version Manager (nvm) allows you to install multiple node versions and choose between them depending on which software you want to support; that is, manage multiple node versions.

Installing Node Version Manager

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

Once you have Node Version Manager installed

  1. Confirm the available remote versions by running nvm ls-remote
  2. Run in your terminal nvm install <version> for example, nvm install 18 to install version 18 of Node
  3. List installed versions with nvm list
  4. Run nvm use 18 to start using version 18 of Node
  5. Note: you can be more explicit, for example: nvm install 14.17.0
2 of 4
29

Install nodejs v20 on Debian and Ubuntu based distributions

step 1 : Download and import the Nodesource GPG key

sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

step 2 : Create deb repository

NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

optional: here we are installing nodejs v20 but if you want to install v18 change NODE_MAJOR=18 in above command. Similarly if you want to install nodejs v16 then change NODE_MAJOR=16.

step 3 : Run Update and Install

sudo apt-get update
sudo apt-get install nodejs -y

congratulations you just installed nodejs

To uninstall nodejs

sudo apt-get purge nodejs &&\
rm -r /etc/apt/sources.list.d/nodesource.list &&\
rm -r /etc/apt/keyrings/nodesource.gpg
🌐
NodeSource
nodesource.com › blog › installing-node-js-tutorial-ubuntu
Installing Node.js Tutorial: Ubuntu
December 8, 2016 - Install Node.js on Ubuntu in this quick tutorial that will get you up and running on your way to building Node.js applications.
🌐
GitHub
github.com › nodesource › distributions
GitHub - nodesource/distributions: NodeSource Node.js Binary Distributions
NodeSource Node.js Binary Distributions. Contribute to nodesource/distributions development by creating an account on GitHub.
Starred by 13.8K users
Forked by 3.1K users
Languages   Shell