Ubuntu – How to fix broken packages in this specific situation

package-management

After running the following four commands my system ended up in broken packages state:

1) apt-get purge nvidia*
2) apt-get autoremove
3) apt-get dist-upgrade
4) apt-get autoremove

I found that unity tweak tool, ubuntu desktop and some essential packages have been removed from the system in the process.
Here is the detailed history of above four commands: http://pastebin.com/PsNNAJ5t
I tried reinstalling all the removed packages from the history from step4 above. It was successful. But the packages removed from step3 are not installing.

And synaptic package manager doesn't let me install anything complaining about broken packages.
I have tried fixing by running
sudo apt-get install -f
sudo dpkg --configure -a
but it did not work

~ $ sudo apt-get install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libbonoboui2-0 libbonoboui2-common libglade2-0 libgnome2-0 libgnome2-bin libgnomecanvas2-0 libgnomecanvas2-common libgnomeui-0 libgnomeui-common libidl-2-0 liborbit2 python-gconf
  python-gnome2 python-pyorbit
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.

When I try to install unity-tweak-tool, it gives me that broken state message and what dependencies it require

sudo apt-get install unity-tweak-tool
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:
 unity-tweak-tool : Depends: unity-webapps-common but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

When I try to install it's dependencies, it continues like a chain complaining about broken packages. At the end of the chain, the dependency doesn't install.

This is the end result if I follow a dependency chain: http://pastebin.com/m01QX442 In the end of the chain, it says E: Package 'qtbase-abi-5-5-1' has no installation candidate or E: Package 'qtdeclarative-abi-5-5-0' has no installation candidate
I also don't understand how my system is operational without ubuntu-desktop
How to fix the system now?

Thanks

Best Answer

For whatever reason dpkg --configure -a was essentially removed from Ubuntu a few releases ago (since 16.04 I believe) so it no longer works and will tell you that -a is an invalid target.

You say "did not work" but this doesn't provide much detail about how apt-get install -f failed, but I can make some assumptions. It probably spits out a name of a package that is in the broken state and what dependencies it requires.

After getting the name of the package that is broken and it's dependencies you can try apt-get remove either the package itself or the dependency. If it's a package you don't care about just remove it, otherwise try removing the dependency and seeing what would go along with that. It's usually caused by some tool wanting to keep a specific version of a library or program. Also take note if some "packages are held back" as this can also keep you from being to resolve dependencies.

Run apt-get install -f and it will continue this process until there are no packages in a broken state.

Related Question