你什么时候会使用 apt-get remove 而不是 apt-get autoremove?

Pea*_*key 17 linux package-management ubuntu apt-get

我知道apt-get remove删除包apt-get autoremove是删除为满足给定包的依赖关系而安装的任何包。因此,例如,如果我安装了 LibreOffice 并且它依赖于 Java 并在我运行命令时将其安装为安装的一部分apt-get libreoffice,为什么我要运行该命令,apt-get remove libreoffice然后是apt-get autoremove?我不能简单地运行命令apt-get autoremove libreoffice吗?或者是组合apt-get removeapt-get autoremove为一个不同的目的是什么?

Myr*_*rys 13

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

如果您总是无一例外地通过 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系统上未使用的问题是一个非常小的问题。它几乎永远不会引起问题,并且大多数依赖项不会占用太多空间。也有例外,但是删除依赖项导致问题的次数多于解决或防止问题的次数。


小智 12

您可以在 apt-get: 的联机帮助页中找到removeautoremovepurgecleanautoclean 的描述以及语法man apt-get

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

下面是vim的完整依赖树示例:

vim 依赖树

您可以通过以下方式获取:

apt-rdepends -d vim > vim.dot
dotty vim.dot
Run Code Online (Sandbox Code Playgroud)

您还可以使用以下方法获取直接依赖项的列表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
Run Code Online (Sandbox Code Playgroud)

所以看起来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
Run Code Online (Sandbox Code Playgroud)

为了让vim工作,我们需要vim-commonvim-runtime包,并且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
Run Code Online (Sandbox Code Playgroud)

正如我们查了一下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
Run Code Online (Sandbox Code Playgroud)

让我们继续安装。一旦我们安装了vim,我们就可以体验removeautoremove之间的区别。让我们先尝试删除

$ 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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

这将删除依赖vim-runtime 以及依赖它的包,即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
Run Code Online (Sandbox Code Playgroud)

它会删除 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
Run Code Online (Sandbox Code Playgroud)

这些是apt-get remove留下的两个包,即使没有其他东西需要它们。

尝试使用 apt-get 0.9.7.9。