couldn't install npm on ubuntu
Solution 1
I solved this issue by following this documentation.
Pointers to remember to work with npm:
mkdir ~/nodejs/ && cd ~/nodejs
sudo apt-get install npm
npm install
npm update
While developing applications, if nodejs needs any particular module then run
cd ~/nodejs
npm install modulename #for example sendgrid
Sometimes, modules needs to install globally; then use
sudo npm install modulename -g"
To remove a module:
cd ~/nodejs
npm uninstall modulename # if locally installed or
sudo npm uninstall modulename -g # if globally installed
npm prune
helps to remove unmet dependencies
Solution 2
This looks like you probably installed the chris-lea node.js ppa which is fine. However, you don't install npm from that ppa as it breaks the way debian packages work. Instead, just install nodejs
. Once that's installed, run npm -v
you should see it's now installed. If you didn't use the chris-lea ppa update your question on what webpage you Googled to find out how to install nodejs on Ubuntu.
Solution 3
Try installing NodeJs like this:
sudo apt-get install nodejs
Since NodeJs installs node and npm
Solution 4
Apt doesn't handle dependancy conflicts well, use snap or aptitude;
sudo aptitude install npm
I had to press "no" to the first solution it proposed, which did not include installing npm (that must be a bug in aptitude) then the second solution I pressed yes
to
hTHen check npm was installed:
npm --version
Solution 5
First, you need to install the PPA in order to get access to its contents:
curl -sL https://deb.nodesource.com/setup_9.x | sudo bash -
(This for version 9, which is the latest version at the time of writing).
And then
sudo apt-get install nodejs
Related videos on Youtube
user3297351
Updated on September 18, 2022Comments
-
user3297351 over 1 year
Tried to install nodejs and npm on ubuntu 12.04. I googled and did it. Now, I could not install npm on machine.
sudo apt-get install npm
Which gives me this
The following packages have unmet dependencies: npm : Depends: nodejs but it is not going to be installed Depends: nodejs-dev Depends: node-request but it is not going to be installed Depends: node-mkdirp but it is not going to be installed Depends: node-minimatch but it is not going to be installed Depends: node-semver but it is not going to be installed Depends: node-ini but it is not going to be installed Depends: node-graceful-fs but it is not going to be installed Depends: node-abbrev but it is not going to be installed Depends: node-nopt but it is not going to be installed Depends: node-fstream but it is not going to be installed Depends: node-rimraf but it is not going to be installed Depends: node-tar but it is not going to be installed Depends: node-which but it is not going to be installed E: Unable to correct problems, you have held broken packages.
-
Peter Krauss over 8 yearsI think nobody say, but
apt-get install npm
must be avoid (!). Check ifnpm -v
is there before to try to install.... (read more below at @MarcoCerpi's answer ) -
GregD about 4 yearsAre you running a 32-bit system? If so, it is not officially supported and you need to use a build from the node unofficial-builds web site.
-
Hank Chan over 3 yearsCan't believe I'm still getting tripped over by this on Ubuntu 20.04...
-
-
Mariano Argañaraz over 8 yearsHow would he run "npm -v" if he cannot install npm...?
-
Mariano Argañaraz over 8 yearsHe cannot install npm men, how could he get to point 3?!
-
Mariano Argañaraz over 8 yearsHow would he run "npm config..." if he cannot install npm...?
-
Peter Krauss over 8 yearsThe "modern"
apt-get install nodejs
do alsonpm
updated installation, so, I understand thatapt-get install npm
must be avoided (!). -
Peter Krauss over 8 years
-
Jonathan almost 6 yearsI removed my PPA and I got ` npm : Depends: node-gyp (>= 0.10.9) but it is not going to be installed`
-
ZZ 5 over 5 yearsdoesn't work with 16.04
-
Gigiux almost 5 yearsno
npm
installed with this... -
Justech about 3 yearsAlso worked for me. Thank you!