How do I resolve `The following packages have unmet dependencies`
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.
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)