清除并重新安装包的命令

清除并重新安装包的命令

有时软件包损坏,需要从头开始重新安装。我可以使用 ,apt-get purge然后使用apt-get install,但之后我必须注意是否有任何依赖软件包被卸载,并记得重新安装它们。

是否有命令可以清除并重新安装软件包,并处理依赖关系?如果某个软件包依赖于正在重新安装的软件包,则应将该软件包保留在原处,或者也应重新安装该软件包。

答案1

虽然这并不可取,但您可以削弱apt并​​直接转到dpkg

例如,取postfixpostfix-dev

$ sudo apt-get purge postfix
Reading package lists... Done
Building dependency tree
Reading state information... Done.
The following packages will be REMOVED:
  postfix* postfix-dev*
0 upgraded, 0 newly installed, 2 to remove and 99 not upgraded.
After this operation, 4449 kB disk space will be freed.
Do you want to continue? [Y/n] n
Abort.

现在我们使用dpkg清除postfix而不删除依赖项:

$ sudo dpkg --purge --force-depends postfix
dpkg: postfix: dependency problems, but removing anyway as you requested:
 postfix-dev depends on postfix (>= 3.1.0-0).
 postfix-dev depends on postfix (<< 3.1.0.0-0).
 postfix-dev depends on postfix (>= 3.1.0-0).
 postfix-dev depends on postfix (<< 3.1.0.0-0).

(Reading database ... 293223 files and directories currently installed.)
Removing postfix (3.1.0-3) ...
Purging configuration files for postfix (3.1.0-3) ...
Processing triggers for libc-bin (2.23-0ubuntu5) ...
Processing triggers for man-db (2.7.5-1) ...

现在重新安装postfix

$ sudo apt-get install postfix
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
  procmail postfix-mysql postfix-pgsql postfix-ldap postfix-pcre sasl2-bin dovecot-common postfix-cdb postfix-doc
The following NEW packages will be installed:
  postfix
0 upgraded, 1 newly installed, 0 to remove and 99 not upgraded.
Need to get 0 B/1152 kB of archives.
After this operation, 3697 kB of additional disk space will be used.
Preconfiguring packages ...
Selecting previously unselected package postfix.
(Reading database ... 293035 files and directories currently installed.)
Preparing to unpack .../postfix_3.1.0-3_amd64.deb ...
Unpacking postfix (3.1.0-3) ...
...

答案2

升级到 ubuntu 21.04 后,我在 postfix 包中遇到了问题,导致多个应用程序行为异常。

我必须彻底清除修复后的软件包

 sudo apt-get purge postfix

然后我重新安装了它

 sudo apt-get install postfix

在安装 Postfix 时会要求配置邮件,但你可以选择

无需配置

然后我重启了设备,一切恢复正常

相关内容