损坏的 Debian 软件包并使用 apt-get -f 进行修复

损坏的 Debian 软件包并使用 apt-get -f 进行修复

当我们安装一个deb最终导致安装中断的软件包时,究竟发生了什么,以及如何apt-get -f补救这种情况(而不是在安装过程中发生这种情况)?

例子:

1)我们安装从以下网址下载的 ferdi 包https://github.com/getferdi/ferdi/releases/tag/v5.3.3

$ dpkg -i ferdi.deb
Selecting previously unselected package ferdi.
(Reading database ... 180829 files and directories currently installed.)
Preparing to unpack .../ferdi_5.3.3_amd64.deb ...
Unpacking ferdi (5.3.3-157) ...
dpkg: dependency problems prevent configuration of ferdi:
 ferdi depends on gconf2; however:
  Package gconf2 is not installed.
 ferdi depends on gconf-service; however:
  Package gconf-service is not installed.
 ferdi depends on libappindicator1; however:
  Package libappindicator1 is not installed.

dpkg: error processing package ferdi (--install):
 dependency problems - leaving unconfigured
Processing triggers for mime-support (3.64) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Errors were encountered while processing:
 ferdi

我们可以看到,由于缺少依赖项,包未正确安装。

2)修复损坏的包装却很轻松:

$ apt-get --fix-broken --yes install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  gconf-service gconf2 libappindicator1 libdbusmenu-gtk4 libindicator7
Suggested packages:
  gconf-defaults-service
The following NEW packages will be installed:
  gconf-service gconf2 libappindicator1 libdbusmenu-gtk4 libindicator7
0 upgraded, 5 newly installed, 0 to remove and 53 not upgraded.
1 not fully installed or removed.
Need to get 993 kB of archives.
After this operation, 1,539 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian unstable/main amd64 gconf-service amd64 3.2.6-6 [415 kB]
Get:2 http://deb.debian.org/debian unstable/main amd64 gconf2 amd64 3.2.6-6 [426 kB]
Get:3 http://deb.debian.org/debian stable/main amd64 libdbusmenu-gtk4 amd64 18.10.20180917~bzr490+repack1-1 [45.7 kB]
Get:4 http://deb.debian.org/debian stable/main amd64 libindicator7 amd64 0.5.0-4 [53.0 kB]
Get:5 http://deb.debian.org/debian stable/main amd64 libappindicator1 amd64 0.4.92-7 [53.3 kB]
Fetched 993 kB in 1s (1,071 kB/s)          
Selecting previously unselected package gconf-service.
(Reading database ... 181193 files and directories currently installed.)
Preparing to unpack .../gconf-service_3.2.6-6_amd64.deb ...
Unpacking gconf-service (3.2.6-6) ...
Selecting previously unselected package gconf2.
Preparing to unpack .../gconf2_3.2.6-6_amd64.deb ...
Unpacking gconf2 (3.2.6-6) ...
Selecting previously unselected package libdbusmenu-gtk4:amd64.
Preparing to unpack .../libdbusmenu-gtk4_18.10.20180917~bzr490+repack1-1_amd64.deb ...
Unpacking libdbusmenu-gtk4:amd64 (18.10.20180917~bzr490+repack1-1) ...
Selecting previously unselected package libindicator7:amd64.
Preparing to unpack .../libindicator7_0.5.0-4_amd64.deb ...
Unpacking libindicator7:amd64 (0.5.0-4) ...
Selecting previously unselected package libappindicator1:amd64.
Preparing to unpack .../libappindicator1_0.4.92-7_amd64.deb ...
Unpacking libappindicator1:amd64 (0.4.92-7) ...
Setting up libindicator7:amd64 (0.5.0-4) ...
Setting up gconf-service (3.2.6-6) ...
Setting up libdbusmenu-gtk4:amd64 (18.10.20180917~bzr490+repack1-1) ...
Setting up libappindicator1:amd64 (0.4.92-7) ...
Setting up gconf2 (3.2.6-6) ...
Setting up ferdi (5.3.3-157) ...
Processing triggers for man-db (2.9.0-1) ...
Processing triggers for libc-bin (2.29-2) ...
  1. 为什么没有安装缺少的依赖项dpkg -i
  2. 为什么apt-get -f能够轻易解决?
  3. 这样做可以吗?或者这会导致系统崩溃?

编辑: 请参阅下面的@thorian93 回答。另请参阅https://askubuntu.com/a/795048/1002165

答案1

据我所知,dpkg没有依赖关系解析。这就是为什么你最终得到损坏的包。包无论如何都会安装,但它在那种状态下不起作用。

Entry aptapt读取dpkg数据库,找到损坏的包和缺失的依赖项。apt 依赖项解析然后它会扫描其配置的镜像以查找依赖项并安装它们。

回答你的第三个问题:这样做是可以的,尽管我建议apt首先通过安装包,或者至少使用gdebi,它也可以进行依赖性解析。

相关内容