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.
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.
I really recommend you install node and npm using nvm. This is the fastest, cleanest and easiest way to do it.
That way, you install NVM simply doing:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
To test that nvm was properly installed, close and re-open Terminal and enter nvm. If you get a nvm: command not found message, your OS may not have the necessary .bash_profile file. In Terminal, enter touch ~/.bash_profile and run the above install script again.
And you are now able to install node typing:
nvm install <version>
For example
nvm install 4.2.1
if you just want to install the latest node version, you can just type
nvm install node
In order to access node and npm as sudo (in order to have <1024 ports) you should run
n=$(which node)
n=${n%/bin/node}
chmod -R 755 $n/bin/*
sudo cp -r $n/{bin,lib,share} /usr/local
I wrote in the terminal the following command lines I hope it is useful for the community.
$ sudo apt install nodejs
$ curl -L https://npmjs.org/install.sh | sudo sh
good luck!