Reputation: 4278
I was using this script to install basic software, but had to interrupt because of slow internet speed.
Now when I hit $ sudo apt-get install npm
, I get following error
yask123@yaskslaptop:~$ sudo apt-get installed npm
E: Invalid operation installed
yask123@yaskslaptop:~$ sudo apt-get install npm
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
npm : Depends: nodejs but it is not going to be installed
Depends: node-abbrev (>= 1.0.4) but it is not going to be installed
Depends: node-ansi (>= 0.3.0-2) but it is not going to be installed
Depends: node-ansi-color-table but it is not going to be installed
Depends: node-archy but it is not going to be installed
Depends: node-block-stream but it is not going to be installed
Depends: node-fstream (>= 0.1.22) but it is not going to be installed
Depends: node-fstream-ignore but it is not going to be installed
Depends: node-github-url-from-git but it is not going to be installed
Depends: node-glob (>= 3.1.21) but it is not going to be installed
Depends: node-graceful-fs (>= 2.0.0) but it is not going to be installed
Depends: node-inherits but it is not going to be installed
Depends: node-ini (>= 1.1.0) but it is not going to be installed
Depends: node-lockfile but it is not going to be installed
Depends: node-lru-cache (>= 2.3.0) but it is not going to be installed
Depends: node-minimatch (>= 0.2.11) but it is not going to be installed
Depends: node-mkdirp (>= 0.3.3) but it is not going to be installed
Depends: node-gyp (>= 0.10.9) but it is not going to be installed
Depends: node-nopt (>= 3.0.1) but it is not going to be installed
Depends: node-npmlog but it is not going to be installed
Depends: node-once but it is not going to be installed
Depends: node-osenv but it is not going to be installed
Depends: node-read but it is not going to be installed
Depends: node-read-package-json (>= 1.1.0) but it is not going to be installed
Depends: node-request (>= 2.25.0) but it is not going to be installed
Depends: node-retry but it is not going to be installed
Depends: node-rimraf (>= 2.2.2) but it is not going to be installed
Depends: node-semver (>= 2.1.0) but it is not going to be installed
Depends: node-sha but it is not going to be installed
Depends: node-slide but it is not going to be installed
Depends: node-tar (>= 0.1.18) but it is not going to be installed
Depends: node-underscore 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.
Upvotes: 153
Views: 580281
Reputation: 495
I had this problem when I'm accidentally mentioned wrong release version in /etc/apt/sources.list file and/or else files in /etc/apt/sources.list.d/ folder.
Despite a fact I've been using debian release, I mistakenly add sources as for ubuntu.
Please, doublecheck correct release you are using:
cat /etc/*release
Upvotes: 1
Reputation: 81
Sometimes dependencies cannot be installed since there are unknown to APT. In some scenarios, activating the universe repository can let APT know that this package is available to be installed.
To add the repo:
sudo add-apt-repository universe && sudo apt update
Upvotes: 1
Reputation: 29669
I solved this like so:
119 mkdir ~/.npm-global
120 npm config set prefix '~/.npm-global'
121 vi ~/.profile
## add .npm-global to start of your PATH var
122 source ~/.profile
Then reinstall a new copy of npm in there:
npm install -g npm
That way, it wont use npm from /usr/lib/node_modules
any more.
Also, if that doesn't work, make sure windows folders are not included in your linux PATH
Upvotes: 0
Reputation: 156
I came across with the same problem. I followed the following steps for the solution: First I removed nodejs and npm. Then, using the information on the webpage "NodeSource Node.js Binary Distributions" related with my operating system, I setup nodejs and npm. The webpage "NodeSource Node.js Binary Distributions" is in the following link:
https://github.com/nodesource/distributions/blob/master/README.md
The installation can be checked using the command given in the "Tests" section with the following link:
https://github.com/nodesource/distributions/blob/master/README.md#tests
Upvotes: 0
Reputation: 25
Ubuntu 22.04 has upgraded libssl1 to libssl3 so you need to add Ubuntu 21.10 source and force the installation of libssl1.
Try this on the terminal:
echo "deb http://security.ubuntu.com/ubuntu impish-security main" | sudo tee /etc/apt/sources.list.d/impish-security.list
sudo apt-get update
sudo apt-get install libssl1.1
Upvotes: 0
Reputation: 99
This worked for me on Pop OS:
Force an overwrite for the Node package (change nodejs_16.9.0-deb-1nodesource1_amd64.deb with your version):
sudo dpkg -i --force-overwrite /var/cache/apt/archives/nodejs_16.9.0-deb-1nodesource1_amd64.deb
Fix the rest of the broken install:
sudo apt -f install
Make sure the rest of your system is properly up to date:
sudo apt update
sudo apt dist-upgrade
credits to matigo : https://askubuntu.com/questions/1362719/error-upgrading-nodejs
Upvotes: 1
Reputation: 18893
What resolved it for me was:
$ apt update
$ apt install nodejs
I had nodejs
installed from the official Debian repositories. This one was installed by unattended-upgrades
. Before that it was installed from NodeSource. The one coming from NodeSource has npm
in the nodejs
package.
Upvotes: 0
Reputation: 842
First, run
sudo apt-get install nodejs-dev node-gyp libssl1.0-dev
then run
sudo apt install npm
Upvotes: 3
Reputation: 711
I tried lots of method but below work like charm....
After this command run these :-
curl -sL https://deb.nodesource.com/setup_14.x 565 | sudo -E bash -
sudo apt-get install -y nodejs
Now check…
node -v
npm -v
Upvotes: 16
Reputation: 7528
This is a bug in the npm package regarding dependencies : https://askubuntu.com/questions/1088662/npm-depends-node-gyp-0-10-9-but-it-is-not-going-to-be-installed
Bugs have been reported. The above may not work depending what you have installed already, at least it didn't for me on an up to date Ubuntu 18.04 LTS.
I followed the suggested dependencies and installed them as the above link suggests:
sudo apt-get install nodejs-dev node-gyp libssl1.0-dev
and then
sudo apt-get install npm
Please subscribe to the bug if you're affected:
bugs.launchpad.net/ubuntu/+source/npm/+bug/1517491
bugs.launchpad.net/ubuntu/+source/npm/+bug/1809828
Upvotes: 5
Reputation: 1602
sudo apt install aptitude
Then
sudo aptitude install npm
Source: https://askubuntu.com/a/978353/458947
Upvotes: 10
Reputation: 111
I just solved this issue. The problem was in version conflict. Nodejs 10 installed with npm. So before installing nodejs - remove old npm. Or remove new node -> remove npm -> install node again.
This is the only way which helped me.
Upvotes: 0
Reputation: 11164
I came to this situation when I installed node js from the latest stable release.
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
It seems this version already comes with a prepackaged NPM. So when I tried to install NPM again, I got this error. If anyone is installing Nodejs in this manner then, it's not needed to install NPM separately.
The following packages have unmet dependencies:
npm : Depends: nodejs but it is not going to be installed
Depends: node-abbrev (>= 1.0.4) but it is not going to be installed
Depends: node-ansi (>= 0.3.0-2) but it is not going to be installed
Depends: node-ansi-color-table but it is not going to be installed
Depends: node-archy but it is not going to be installed
Depends: node-block-stream but it is not going to be installed
Depends: node-fstream (>= 0.1.22) but it is not going to be installed
Depends: node-fstream-ignore but it is not going to be installed
Depends: node-github-url-from-git but it is not going to be installed
Depends: node-glob (>= 3.1.21) but it is not going to be installed
Depends: node-graceful-fs (>= 2.0.0) but it is not going to be installed
Depends: node-inherits but it is not going to be installed
Depends: node-ini (>= 1.1.0) but it is not going to be installed
Depends: node-lockfile but it is not going to be installed
Depends: node-lru-cache (>= 2.3.0) but it is not going to be installed
Depends: node-minimatch (>= 0.2.11) but it is not going to be installed
Depends: node-mkdirp (>= 0.3.3) but it is not going to be installed
Depends: node-gyp (>= 0.10.9) but it is not going to be installed
Depends: node-nopt (>= 3.0.1) but it is not going to be installed
Depends: node-npmlog but it is not going to be installed
Depends: node-once but it is not going to be installed
Depends: node-osenv but it is not going to be installed
Depends: node-read but it is not going to be installed
Depends: node-read-package-json (>= 1.1.0) but it is not going to be installed
Depends: node-request (>= 2.25.0) but it is not going to be installed
Depends: node-retry but it is not going to be installed
Depends: node-rimraf (>= 2.2.2) but it is not going to be installed
Depends: node-semver (>= 2.1.0) but it is not going to be installed
Depends: node-sha but it is not going to be installed
Depends: node-slide but it is not going to be installed
Depends: node-tar (>= 0.1.18) but it is not going to be installed
Depends: node-underscore 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.
Upvotes: 36
Reputation: 3366
First of all try this
sudo apt-get update
sudo apt-get clean
sudo apt-get autoremove
If error still persists then do this
sudo apt --fix-broken install
sudo apt-get update && sudo apt-get upgrade
sudo dpkg --configure -a
sudo apt-get install -f
Afterwards try this again:
sudo apt-get install npm
But if it still couldn't resolve issues check for the dependencies using sudo dpkg --configure -a
and remove them one-by-one . Let's say dependencies are on npm then go for this ,
sudo apt-get remove nodejs
sudo apt-get remove npm
Then go to /etc/apt/sources.list.d and remove any node list if you have. Then do a
sudo apt-get update
Then check for the dependencies problem again using sudo dpkg --configure -a
and if it's all clear then you are done .
Later on install npm again using this
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
The answer above will work for general cases also(for dependencies on other packages like django ,etc) just after first two processes use the same process for the package you are facing dependency with.
Upvotes: 79
Reputation: 3002
Installing nodejs will install npm ... so just remove nodejs then reinstall it: $ sudo apt-get remove nodejs
$ sudo apt-get --purge remove nodejs node npm
$ sudo apt-get clean
$ sudo apt-get autoclean
$ sudo apt-get -f install
$ sudo apt-get autoremove
Upvotes: 22
Reputation: 502
The command to have Ubuntu fix unmet dependencies and broken packages is
sudo apt-get install -f
from the man page:
-f, --fix-broken Fix; attempt to correct a system with broken dependencies in place. This option, when used with install/remove, can omit any packages to permit APT to deduce a likely solution. If packages are specified, these have to completely correct the problem. The option is sometimes necessary when running APT for the first time; APT itself does not allow broken package dependencies to exist on a system. It is possible that a system's dependency structure can be so corrupt as to require manual intervention (which usually means using dselect(1) or dpkg --remove to eliminate some of the offending packages)
Ubuntu will try to fix itself when you run the command. When it completes, you can test if it worked by running the command again, and you should receive output similar to:
Reading package lists... Done Building dependency tree Reading state information... Done 0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
Upvotes: 35
Reputation: 2087
If sudo apt-get install -f <package-name>
doesn't work, try aptitude:
sudo apt-get install aptitude
sudo aptitude install <package-name>
Aptitude will try to resolve the problem.
As an example, in my case, I still receive some error when try to install libcurl4-openssl-dev
:
sudo apt-get install -f libcurl4-openssl-dev
So i try aptitude, it turns out I have to downgrade some packages.
The following actions will resolve these dependencies: Keep the following packages at their current version: 1) libyaml-dev [Not Installed] Accept this solution? [Y/n/q/? (n) The following actions will resolve these dependencies: Downgrade the following packages: 1) libyaml-0-2 [0.1.4-3ubuntu3.1 (now) -> 0.1.4-3ubuntu3 (trusty)] Accept this solution? [Y/n/q/?] (Y)
Upvotes: 197
Reputation: 1839
Node comes with npm installed so you should have a version of npm. However, npm gets updated more frequently than Node does, so you'll want to make sure it's the latest version.
Try
sudo npm install npm -g
Upvotes: -7