sudo apt install nodejs
sudo apt install npm
Answer from abdelrahman aboneda on Stack Overflowsudo apt install nodejs
sudo apt install npm
nvm is for installing node not npm, npm will be installed
What you're doing with nvm install npm, is attempting to install a node version called npm.
Do nvm install 14, let it run, check for errors, then once installed your have npm.
Videos
How do I update npm Ubuntu?
How to install npm on Ubuntu 20.04?
Is nvm better than apt for installing npm?
Fresh installation
Use the NodeSource PPA. For details look at the installation instructions. First, choose the Node.js version you need and add the sources for it:
v=8 # set to 4, 5, 6, ... as needed
curl -sL https://deb.nodesource.com/setup_$v.x | sudo -E bash -
Then install the Node.js package.
sudo apt-get install -y nodejs
P.S.: curl package must be installed on server for these code lines.
Upgrading
If you have nodejs already installed and want to update, then first remove current instalation and install it again using scripts above.
sudo apt-get purge nodejs npm
Generally speaking, loading arbitrary data from a URL into a root shell session is not a good idea and I wish people would stop peddling it as a solution for everything - "Please just run this script I'm sending you, and also while we're at it - I have a bridge you'd probably be interested in purchasing".
As an alternative, here's the "Ubuntu Way" of doing the same, where you can see how the system is being updated and know what repositories and what keys are added to your system configuration:
curl https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb https://deb.nodesource.com/node_7.x $(lsb_release -sc) main"
sudo apt-get update
sudo apt-get install nodejs
And here's the "post deprecation of apt-key way" of doing the same thing:
curl https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_7.x $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/nodejs.list
sudo apt update
sudo apt install nodejs
This is for the latest (at time of writing) Nodejs version 7. Other versions can also be gotten with a simple change to the repo URL - consult nodesource.com documentation for details.