12.04 修复 apt-get 包管理器

12.04 修复 apt-get 包管理器

I was installing PostgreSQL 9.4 and pgAdmin on my Ubuntu 12.04 and after that I needed to install Postgis extension for Postgres as well. Before the Postgis step all was fine. There I tried with compiling the source code as well as with dpkg -i .deb method to install and both gave an error about a file missing - libpq-fe.h. I found out it's in a libpq-dev package, so did sudo apt-get install libpq-dev. This returned me that this package is already installed. Though a folder in which the file libpq-fe.h (and others) should be was empty. So my guess was to remove libpq-dev and install it again. I tried both with sudo apt-get remove ... and sudo apt-get remove --purge ....

From here the package manager broke and right now any attempt to install a package (below Wine, just for example) or do a sudo apt-get upgrade returns:

adambo@adam-pc:~/Downloads/postgis-2.2.2$ sudo apt-get install wine
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 libpq-dev : Depends: libpq5 (= 9.1.20-0ubuntu0.12.04) but 9.5.3-1.pgdg12.4+1 is to be installed
 postgresql-server-dev-9.4 : Depends: libpq-dev (>= 9.4~) but 9.1.20-0ubuntu0.12.04 is to be installed
 wine : Depends: wine1.4 but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

What I've tried:

  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get clean
  • sudo apt-get remove
  • sudo apt-get autoremove
  • sudo apt-get install -f

Some returned regular results (or nothing), but some returned same as in code above.

I also tried to remove libpq-dev and libpq5 packages, but any attempt resulted in the code above again.

But sudo apt-get install -f gives me:

adambo@adam-pc:~/Downloads/postgis-2.2.2$ sudo apt-get install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following extra packages will be installed:
  libpq-dev
Suggested packages:
  postgresql-doc-9.5
The following packages will be upgraded:
  libpq-dev
1 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
1 not fully installed or removed.
Need to get 0 B/228 kB of archives.
After this operation, 141 kB disk space will be freed.
Do you want to continue  [Y/n]? Y
dpkg: dependency problems prevent configuration of libpq-dev:
 libpq-dev depends on libpq5 (= 9.1.20-0ubuntu0.12.04); however:
  Version of libpq5 on system is 9.5.3-1.pgdg12.4+1.
dpkg: error processing libpq-dev (--configure):
 dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                                              Errors were encountered while processing:
 libpq-dev
E: Sub-process /usr/bin/dpkg returned an error code (1)


What could I do to at least restore apt-get functionality?

答案1

After tries and fails I tried with Aptitude (fortunately installed already) and pressed g to install/remove/repair packages. There I followed what it proposed to remove and... Error disappeared. libpq-dev was removed. Though some of other packages I actually need were removed as well.

Therefore I recommend it to people who are able to easily restore and reinstall missing packages.

答案2

When discovering that files from libpq-dev are missing, the command to run is:

sudo apt-get install --reinstall libpq-dev

此命令不再理会依赖的包,相反,apt-get remove它会将你拖入依赖混乱之中。

相关内容