apt -f install 命令的意义

通常在用dpkg -i 命令安装了一个deb包之后,如果执行apt upgrade,有时候会遇到错误提示。

这种情况下,如果在dpkg -i安装了deb包之后马上执行apt -f install命令,好像会好一些。

我查了一下apt-get(8)[apt-get(8) — apt — Debian buster — Debian Manpages],只提到了修复有问题的包。

我的问题是,通常并不建议使用dpkg -i命令来安装包;那么apt -f install命令是否可以让dpkg -i命令更好用,或者说,dpkg -i命令加上apt -f install命令一起用,是不是会让依赖问题出现的概率更小一些?

如果是这样的话,那没事装个deb包就更有底气一些了~

安装本地deb包也是建议直接使用
apt install ./xx.deb
安装本地deb也会自动解决依赖问题。

2 个赞

看来我的资料有点过时了~

二楼的方法是更好的,apt现在可以直接安装本地的deb包,会自动解决依赖问题

1 个赞

Debian管理员手册:

If the package to install has been made available to you under the form of a simple .deb file without any associated package repository, it is still possible to use APT to install it together with its dependencies (provided that the dependencies are available in the configured repositories) with a simple command: apt install ./path-to-the-package.deb. The leading ./ is important to make it clear that we are referring to a filename and not to the name of a package available in one of the repositories.

Debian参考手册也有类似的建议:

dpkg -i <package_name>-<debian_version>.deb
安装一个本地的软件包到系统中
apt install /path/to/<package_filename>.deb
安装本地软件包到系统中,同时尝试自动解决依赖

该文档给出了警告:

系统管理员应该小心使用低级的软件包工具(例如 “dpkg -i …” 和 “debi …”),它们不会自动处理所需的软件包依赖。 dpkg 的命令行选项 “--force-all” 和类似的选项(参见 dpkg(1))只适用于高手。没有完全理解它们的效果却使用它们会破坏你的整个系统。

APT用户手册解释了-f选项:

There are two ways a system can get into a broken state like this. The first is caused by dpkg missing some subtle relationships between packages when performing upgrades. The second is if a package installation fails during an operation. In this situation a package may have been unpacked without its dependents being installed.
The second situation is much less serious than the first because APT places certain constraints on the order that packages are installed. In both cases supplying the -f option to apt-get will cause APT to deduce a possible solution to the problem and then continue on. The APT dselect method always supplies the -f option to allow for easy continuation of failed maintainer scripts.
However, if the -f option is used to correct a seriously broken system caused by the first case then it is possible that it will either fail immediately or the installation sequence will fail. In either case it is necessary to manually use dpkg (possibly with forcing options) to correct the situation enough to allow APT to proceed.

总结:建议安装本地deb软件包时使用命令apt install ./path-to-the-package.deb

1 个赞

感觉明白了,我之前还在想,包前面弄个./是不是多余,原来./很重要~