If you are unable to install/remove any new packages using package managers, and seemingly there is no other option than to backup your data and do a clean install of the system, you may try this first:
sudo dpkg -l | grep -v '^ii'
Then for each packages which have something other than ii
in the first and second column, or an ..R
in the third column, remove them using:
sudo dpkg --purge package_name1 package_name2 ...
or
sudo dpkg --purge --force-depends package_name1 package_name2 ...
(Instead of --force-all
you may use one or combine more as described in dpkg --force-help
. e.g. for rc
you do not need to --force-...
anything, for iHR
it is enough to use --force-remove-reinstreq
, etc.)
sudo apt-get clean
sudo apt-get update
sudo apt-get --fix-broken install
Hopefully, this should fix the broken package.
The i
character is usually installed state or desired state. There is a description at: How to interpret the status of dpkg (–list)
The first column in the output of sudo dpkg -l | grep '^.[^i]'
represents the status of a package and represented by two or three characters. e.g. ii, rc, iU, etc. Below is a list of the possible characters and their meaning:
First character: This specified the desired state. The possible values are:
- u : Unknown (an unknown state)
- i : Install (marked for installation)
- r : Remove (marked for removal)
- p : Purge (marked for purge)
- h : Hold (held package)
Second character: This specified the current state (whether it is installed or not). The possible values are:
- n : Not (the package is not installed)
- i : Installed (the package is successfully installed)
- c : Configuration files (Configuration files are present)
- u : Unpacked (the package is unpacked)
- f : Failed-Cfg (failed to remove configuration files)
- h : Half-Installed (the package is only partially installed)
- W : trig-aWait
- t : trig-pend
Third character: This specified the error state. The possible values are:
- R : Reinstall-required (the package must be reinstalled)
An example:
To demonstrate a broken package, I downloaded a bunch of .deb
packages required for npm
package. I then removed two of the packages there and installed the rest in the directory with sudo dpkg -i *
and hence a broken package dependency situation was created. Then I did as stated above.
The following was the result of sudo dpkg -l | grep '^.[^i]'
command:
iU node-cacache 15.0.5+~cs13.9.21-3 all fast, fault-tolerant, disk-based, data-agnostic, content-addressable cache
iU npm 8.5.1~ds-1 all package manager for Node.js
I then purged all those marked other than ii
e.g. the iU
s using commands:
sudo dpkg --purge --force-all npm
sudo dpkg --purge --force-all node-cacache
And then followed the rest of the procedure.
And, lastly having synaptic
package manager beforehand in your system is a lot helpful in resolving broken packages, among other benefits. You can install synaptic with sudo apt-get install synaptic
.
sudo apt-get install ia32-libs
) and the output from that command. Also, doessudo apt-get dist-upgrade
show any available updates?