Installing Node.js on Ubuntu 20.04
There are two sensible ways to install Node.js on Ubuntu 20.04. A NodeSource package works well for a machine that needs one system-wide version. nvm is usually more convenient on a development machine where projects need different versions.
Ubuntu 20.04 is an older release, and Node.js versions change. Check that the Node release you choose still supports the operating system before installing it.
Install a system-wide version with NodeSource
Update the package index first:
sudo apt update
sudo apt upgrade
NodeSource publishes setup instructions for its currently supported releases. The old setup_lts.x command may not select the version you expect today, so use the command from the NodeSource documentation for the major version you need.
After adding that repository, install Node.js:
sudo apt install nodejs
Then verify both executables:
node --version
npm --version
Use nvm for project-specific versions
nvm installs Node versions for your user account and lets you switch between them. Use the current installer from the nvm repository; version-pinned installation commands age quickly.
After installing it, reopen the terminal or load the shell configuration. On a Bash setup that may be:
source ~/.bashrc
Install the current long-term-support release with:
nvm install --lts
Or install a particular major version:
nvm install 20
I would not install Node through NodeSource and nvm unless there is a clear reason to keep both. On a server, a system package gives you one predictable executable. For local development, nvm makes per-project versions much less awkward.