你什么时候在apt-get autoremove上使用apt-get remove?


16

我明白那个 apt-get remove 删除包和 apt-get autoremove 是删除为满足给定包的依赖项而安装的所有包。因此,例如,如果我安装了LibreOffice并且它依赖于Java,并在运行命令时将其安装为安装的一部分 apt-get libreoffice,为什么我要运行命令 apt-get remove libreoffice 其次是 apt-get autoremove?我不能简单地运行命令 apt-get autoremove libreoffice?或者是组合 apt-get remove 和 apt-get autoremove 出于不同的目的?

Answers:


11

这取决于您对可靠性跟踪器的信任程度。虽然几乎总是正确的,但有时您希望保留依赖性,特别是当您是开发人员或高级用户安装不在存储库中的软件时。

如果你总是通过apt-get安装软件,毫无例外,并且信任所有的依赖关系是正确的(他们通常是这样),那么你可以使用 apt-get autoremove 并且通过移除不再具有任何需要它们的包装的包装来获得少量的驱动器空间并减少潜在安全漏洞的暴露。

但是,如果您手动安装软件,或开发软件,或者不想处理可能的依赖性错误,那么不使用autoremove清除可能未使用的软件包可能是更安全的选择。无论你是否使用 apt-get autoremove 无论何时或不然,您将始终使用删除软件 apt-get remove Package

例如,如果我安装 AwesomePackage,这可能取决于 AwesomeLibrary, 因此 AwesomeLibrary 将自动安装为 扶养 。当我删除 AwesomePackage 使用autoremove,只要没有其他包 AwesomeLibrary 作为依赖项,它也将被卸载。但如果 SuperPackage 也需要 AwesomeLibrary,或者如果我已安装 AwesomeLibrary 明确地自己,而不是让它作为依赖自动进入( apt-get install AwesomeLibrary ),然后autoremove不会摆脱它。

它不是默认的原因是 AwesomeLibrary 在系统上,未使用,是一个非常小的问题。它几乎不会导致问题,大多数依赖性不会占用太多空间。有一些例外,但删除依赖性的时间将导致问题超过解决或防止问题的次数。


对不起Myrddin Emrys。你在那里迷了我。所以让我试着理解你说的话。因此,例如,如果我使用apt-get安装了libreoffice,它会安装一大堆依赖项,假设我没有安装它们。现在,如果我决定摆脱libreoffice,我想我会跑 apt-get remove libreoffice
— PeanutsMonkey

如果我希望它安装的依赖项保持正确吗?如果我想摆脱libreoffice及其相关的依赖关系,假设没有其他程序使用,我认为我会运行命令 apt-get autoremovelibreoffice?那是对的吗?
— PeanutsMonkey

这绝对是正确的@PeanutsMonkey。 Autoremove也将删除 其他包裹 命名包所依赖的,如果它们不再需要,并且没有故意单独安装。
— Myrddin Emrys

实际上,这不是绝对正确的;我的答案中有一些不正确的语法(正如@cooper指出的那样)。我已经在上面的答案中纠正了这一点。 apt-get autoremove 是一个单独的命令 apt-get remove Package,我为最初的错误信息道歉。
— Myrddin Emrys

谢谢Myrddin Emrys。对不起,如果我是一个n00b。当你这么说的时候 There are exceptions, but the times when removing a dependancy will cause problems outnumber the times when it will solve or prevent a problem。你到底是什么意思?
— PeanutsMonkey

10

你可以找到的描述 去掉 , 的autoremove , 清除 , 清洁 和 自动清洁 ,以及apt-get的联机帮助页的语法: man apt-get。

如果你在阅读之后仍然不确定(我是),澄清它的最好方法就是尝试一下。

下面是完整依赖关系树的示例 VIM :

vim-dependency-tree

你可以得到它:

apt-rdepends -d vim > vim.dot
dotty vim.dot

您还可以使用获取直接依赖项的列表 apt-cache depends (看到 声明包之间的关系 了解更多信息):

$ apt-cache depends vim
vim
  Depends: vim-common
  Depends: vim-runtime
  Depends: libacl1
  Depends: libc6
  Depends: libgpm2
  Depends: libselinux1
  Depends: libtinfo5
  Suggests: <ctags>
    exuberant-ctags
  Suggests: vim-doc
  Suggests: vim-scripts

所以它看起来像 VIM 取决于许多软件包,让我们尝试安装它 apt-get install 看看会发生什么:

$ sudo apt-get install vim
...
The following extra packages will be installed:
  vim-common vim-runtime
Suggested packages:
  ctags vim-doc vim-scripts
The following NEW packages will be installed:
  vim vim-common vim-runtime
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
After this operation, 25.1 MB of additional disk space will be used.
Do you want to continue [Y/n]? n

为了得到 VIM 我们需要工作 VIM常见 和 VIM运行时 包和 apt-get 会照顾它。我们可以验证它 dpkg -s pkg... (看到 man dpkg 有关状态的更多信息):

$ sudo dpkg -s libc6
Package: libc6
Status: install ok installed        // we already have it, no need to install

$ sudo dpkg -s vim-common
Package: vim-common
Status: deinstall ok config-files   // we don't have it, have to install

正如我们检查了什么 VIM 取决于,我们还可以检查其他东西依赖于相同的包 VIM 运用 apt-cache rdepends。我们应该看到 VIM 其中(可能)其他事情:

$ apt-cache rdepends vim-common
vim-common
Reverse Depends:
  vim-latexsuite
  vim-addon-manager
  vim-tiny
  vim-nox
  vim-gtk
  vim-gnome
 |vim-dbg
  vim-athena
  vim                               // there it is

让我们继续安装。一旦我们安装完毕 VIM 我们可以体验到之间的区别 去掉 和 的autoremove 。让我们尝试 去掉 第一:

$ sudo apt-get remove vim
...
The following packages will be REMOVED:
  vim
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 1,922 kB disk space will be freed.
Do you want to continue [Y/n]? n

apt-get remove 然后会删除 VIM 但 不是它的依赖性让它们落后 。我们现在尝试删除其中一个 VIM 依赖:

$ sudo apt-get remove vim-runtime
...
The following packages will be REMOVED:
  vim vim-runtime
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 24.8 MB disk space will be freed.
Do you want to continue [Y/n]? n

这将消除依赖性 VIM运行时 以及依赖它的包装 ,即 VIM 。出于好奇,让我们看看如果我们删除了较低的依赖项会发生什么 VIM 的依赖树:

$ sudo apt-get remove libgpm2
...
The following packages were automatically installed and are no longer required:
  libgtkglext1 libqtassistantclient4 libtiff-tools libtiff5 python-qt4
  python-sip python-sqlalchemy python-sqlalchemy-ext
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  anki cheese gimp gimp-gmic gimp-plugin-registry gnome-control-center      // !
  gnome-media gnome-video-effects gstreamer0.10-plugins-good libaa1         // !
  libcheese-gtk21 libcheese3 libgpm2 mplayer quodlibet vim vlc w3m          // !
0 upgraded, 0 newly installed, 18 to remove and 0 not upgraded.
After this operation, 63.1 MB disk space will be freed.
Do you want to continue [Y/n]? n

它会删除vim和许多好东西!

我们继续吧 apt-get remove vim 然后。一旦我们完成它,我们应该有一些剩菜。如果我们现在尝试 的autoremove 我们可以看到:

$ sudo apt-get autoremove
...
The following packages will be REMOVED:
  vim-common vim-runtime
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 23.2 MB disk space will be freed.
Do you want to continue [Y/n]? y

这是两个包 apt-get remove 即使没有别的东西需要它

用apt-get 0.9.7.9进行实验。


4

根据这个: http://ubuntuforums.org/showthread.php?t=996053 autoremove将删除其他程序不需要的所有包。你会做'apt-get autoremove',而不是'apt-get autoremove libreoffice'。删除不需要的软件包不仅可以释放一点磁盘空间,还可以减少系统的“攻击面”。


我可以看到未使用的库可以是一个攻击向量,但对于我来说,这似乎是一个非常小的问题,相对于不正确删除的重大痛苦(我已经看过不止一次)。感谢您提供有关使用方法的信息...我实际上已经描述了autoremove不正确(我不自己使用它,所以没有意识到),谢谢你的纠正。
— Myrddin Emrys

3

remove 将删除指定的程序而 autoremove 将包括否则不再使用的依赖项。

此外,如果您想释放驱动器空间,一个有用且安全的命令是......

sudo apt-get clean

这将删除/ var / cache / apt / archives中的aptitude缓存


很抱歉是这样的n00b,但我不太关注。所以如果我运行命令 apt-get remove libreoffice,我认为它只会删除libreoffice。是对的吗?但是如果我运行命令 apt-get autoremove libreoffice,这不仅会删除libreoffice,还会删除它的依赖关系?
— PeanutsMonkey

那是对的。所以,让我说我安装 neverball 和 neverball 取决于一个叫做的包 libisfun。如果我 apt-get remove neverball 然后它将删除只是 neverball 包。如果我 apt-get autoremove neverball 那么它会删除 neverball 和 libisfun 如果 libisfun 不依赖于任何其他应用程序。
— kobaltz
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.