“sudo apt-get install foo-”导致删除 foo 包以及依赖于它的所有内容

“sudo apt-get install foo-”导致删除 foo 包以及依赖于它的所有内容

在命令提示符下工作时,我意外地输入了以下命令:

sudo apt-get install python3-

然后 ubuntu 开始删除 python3 以及依赖它的所有内容(包括 Firefox 等等)。幸运的是,我立即关闭了该终端,并通过检查dpkg日志文件恢复了所有内容,但我想知道为什么install命令应该像 remove 一样?

这是一个错误吗?

想象一下这样的情况:您正在寻找一个包名称(按两次 Tab 键),然后按下 Enter 键来查看各种可能性,而这些 Enter 键仍留在键盘缓冲区中……你……apt-get正在您眼前删除整个安装。

答案1

这显然是 的一个特点apt

来自命令手册apt-get手册页图标

如果在软件包名称后附加连字符(中间没有空格),则已安装的已识别软件包将被删除。同样,可以使用加号来指定要安装的软件包。后面这些功能可用于覆盖 apt-get 冲突解决系统做出的决定。


使用已安装的包和附加到包末尾的连字符进行模拟会给出以下输出:

$ apt-get install -s retext-
NOTE: This is only a simulation!
      apt-get needs root privileges for real execution.
      Keep also in mind that locking is deactivated,
      so don't depend on the relevance to the real current situation!
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  retext-wpgen
Use 'apt-get autoremove' to remove it.
The following packages will be REMOVED:
  retext
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Remv retext [3.1.3-1]

类似地,对于卸载的包并且在包末尾附加一个加号,我得到以下输出:

$ apt-get remove -s googlecl+
NOTE: This is only a simulation!
      apt-get needs root privileges for real execution.
      Keep also in mind that locking is deactivated,
      so don't depend on the relevance to the real current situation!
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  python-gdata
Suggested packages:
  python-gdata-doc
The following NEW packages will be installed:
  googlecl python-gdata
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Inst python-gdata (2.0.17-1 Ubuntu:12.10/quantal [all])
Inst googlecl (0.9.13-1.1 Ubuntu:12.10/quantal [all])
Conf python-gdata (2.0.17-1 Ubuntu:12.10/quantal [all])
Conf googlecl (0.9.13-1.1 Ubuntu:12.10/quantal [all])

答案2

刚刚在包后面尝试了这个减号(或破折号),是的,apt-get 的行为就像remove

有趣的是,我不知道这个功能apt-get。这个减号对每个包都有效。我尝试使用smplayer-firefox-但总是表现得像remove。所以我唯一能想到的是,包末尾的破折号被视为apt-get减号,install命令转换为remove

如果你想安装有关 python3 的所有内容,那么你必须在这个破折号(减号)后面添加一个星号

sudo apt-get install python3-*

一开始我以为这只是一个冲突问题,但事实并非如此。有时当你安装某个包并与其他包发生冲突时,已安装的包会因为新安装的包而被删除,但我们这里的情况并非如此。

我们今天学到了一些有用的东西。

来自 apt-get 的手册页。要通过终端阅读手册页,请输入man apt-get

如果在软件包名称后附加连字符 (-)(中间没有空格),则将删除所标识的软件包(如果该软件包当前已安装)。同样,可以使用加号 (+) 来指定要安装的软件包。后面这些功能可用于覆盖 apt-get 冲突解决系统做出的决定。

最终并不是一个新的选项或者一些奇怪的东西,只是我们没有仔细阅读手册页。

相关内容