Fixing your broken package manager (apt-get, synaptic, aptitude) using dpkg after a failed manual install of a package or misinstalled dependancy.

osirisgothra
  10 years ago
  5

This is just a quick tutorial I thought it would be good for people to know that there is hope if you are in the process of installing some *new* release of your favorite software that is not yet in the repository, has not ppa nor backport, and no complete package -- just bits of packages. This doesnt apply to source compiling, that is a whole other ball of wax, by the way. I will also try to sneak in my "3 golden rules of using linux for novice to intermediate users".

Okay, I have done this a many times in the last year, I'll be upgrading some software that I want to try the *new* version of. I'll go through and get the depdencies, and install them one by one. Along the way I realize I did something wrong because I get a message from my package manager that 700+ packages need to be removed due to a package failing. This is where my first rule comes in:

rule #1, ALWAYS (and I mean ALWAYS) keep a log, snapshot, or text history (even if you dont get the actual state, just some basic history text will even do) of ALL packages you install by hand, and (if you can) the output of the command during the process. The easiest way is to function your dpkg or apt-get commands to write the output to a log file as well, there are many ways to do this (see scripting with bash for more details).

Okay, so, for example, I upgraded libfontconfig the other day -- wanting to check out software that used it, and not realizing it broke a bunch of other packages. So what I did find out was that when I tried to install anything I had a message telling me to "use 'sudo apt-get install -f' to 'fix' it" which led me to the 700+ removals prompt. Obviously I don't want to uninstall my entire system. So how do we get around this? Like this:

STEP 1 - FIND THE PACKAGE

First, search your current repository for the 'standard' version of your package, this is done by first finding the right name (in this case libfontconfig is the offender)

$ apt-cache search libfontconfig

libfontconfig1 - generic font configuration library - runtime
libfontconfig1-dbg - generic font configuration library - debugging symbols
libfontconfig1-dev - generic font configuration library - development

STEP 2 - GET AND VERIFY THE PACKAGE DETAILS

obvously we don't want the -dbg (binaries compiled with debug symbols) or -dev (the source libraries and headers) files, we just want the release libraries, but we cant use apt-get to install it right? so we have to do some work... first we need to know WHAT we are getting... so next do this:

$ apt-cache show libfontconfig1

Package: libfontconfig1
Priority: optional
                                        . . .
Architecture: i386
Source: fontconfig
Version: 2.8.0-3ubuntu9
Provides: libfontconfig
                                        . . .

Filename: pool/main/f/fontconfig/libfontconfig1_2.8.0-3ubuntu9_i386.deb
                                        . . .
Multi-Arch: same
Description-md5: 79e15bc25852b501452288a133d57a43
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 5y
Task: [...]
                                                                              

The reason you want to do this is for the Filename, not the entire path, just the file's name, in this case it is libfontconfig1_2.8.0-3ubuntu9_i386.deb, which you will need to know for step 4. This step is also important because you need to verify that it IS the package that you want to put back. An example where this goes wrong is if you have installed some other repository, which would be evident here. (In this case, you need to remove the repository from your /etc/apt/sources.list.d/[name].list. After you do this you have to use apt-get update to reflect the changes). If the package is indeed the one you need, proceed to step 3.

STEP 3 -- DOWNLOAD THE PACKAGE

You might be tempted to get on google and search and download the package there. DONT, its much easier to do it this way (and you get EXACTLY what you need for sure this way). This also brings me to rule #2:

rule#2 - if something in linux seems hard, there is probably a much, much easier way of doing it (this rings true for all corners: the os, developers, artists, entertainment, etc)

All you need at this point is the package's name you got from step 1, using this command:

$ apt-get download libfontconfig1

Get 1: downloading libfontconfig1 2.8.0-3ubuntu9.1 [125kb]
Fetched 125kb in 0s [ 626kb/s]

 

Notice you don't need to use sudo (yet) at this point. And also notice, that you are told what you are downloading but you dont know the filename of what you just got, unless you either type 'ls' or got the file's name from step 2.  One reason for step 2 is to verify and to potentially have this information if you were ever to write a fix-my-library script, the other is if you have a VERY long list of files in your download directory and many simmilarly named files to sift through, having the filename ahead of time saves you from having to squint looking at a long list of files. Now that you have your file, you go to the final step.

STEP 4 -- PATCHING THE HOLE IN THE BOAT

A broken package manager is like a sinking boat, the more stuff you need to install, the more the system goes down, the more software you bring on board, the more software you can't use, it really is something everyone does NOT want to be on.  To fix this "hole" we use dpkg, because remember "apt-get install" (or any other  'smart' package manager) still doesnt work at this point!  Just do this (finally):

$ sudo dpkg --install ./libfontconfig1_2.8.0-3ubuntu9_i386.deb

Notice you need sudo for this, it is a MUST unless you are root (even if you have admin rights or even are a member of the 'root' group, unless you foolishly changed ALL your permissions on your system files to change your UID to root when you run dpkg and all the related tools and libraries, which is a BIG no-no). Anyways, in this example, the hole is now patched, to confirm it is so, we use this to check it out:

$ sudo apt-get install -f

Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove, and 26 not upgraded.


 

Hey thats good enough for me!!  I now have a working system again... yay!!

Now, for the next and final rule...

rule #3  Novice users especially, NEVER use dpkg unless you know exactly what you are doing!

Dont forget the other two rules either...they all go hand in hand

I hope this little mini-tutorial helps someone, even one person and it will serve it's purpose.

Comments
jahid_0903014 10 years ago

nice tutorial


Hammer459 10 years ago

Using apt should never be suggested to anyone below intermediate level due to the risk of screwing up your system. Using Software Manager should be enough for most novice users.
Having said that.... Nice tutorial that should work. I have not had time to check as I always check dependencies prior to installing libs....