apt-mark 学习笔记

on 2024-11-27

今天在自动更新脚本的时候,可能是误把libfuse2包给删除了,导致appimage无法运行,提示找不到libfuse2库。

之前也有遇到过KDE被删除的情况,于是在网上搜索,发现可以使用apt-mark来锁定包,防止被自动删除。

首先贴一下apt-mark的帮助信息:

apt-mark -h

apt 2.9.14 (amd64)
Usage: apt-mark [options] {auto|manual} pkg1 [pkg2 ...]

apt-mark is a simple command line interface for marking packages
as manually or automatically installed. It can also be used to
manipulate the dpkg(1) selection states of packages, and to list
all packages with or without a certain marking.

Most used commands:
  auto - Mark the given packages as automatically installed
  manual - Mark the given packages as manually installed
  minimize-manual - Mark all dependencies of meta packages as automatically installed.
  hold - Mark a package as held back
  unhold - Unset a package set as held back
  showauto - Print the list of automatically installed packages
  showmanual - Print the list of manually installed packages
  showhold - Print the list of packages on hold

See apt-mark(8) for more information about the available commands.
Configuration options and syntax is detailed in apt.conf(5).
Information about how to configure sources can be found in sources.list(5).
Package and version choices can be expressed via apt_preferences(5).
Security details are available in apt-secure(8).

其中需要用到的就是manual这个subcommand, 通过将包标记为手动安装,这样就不会被autoremove掉了。

其次是minimize-manual这个subcommand。很多时候我们在安装软件的时候,实际上是安装的一个meta package。 我们在删除软件的时候,如果直接 remove 或者 purge 这个meta package,它一并下载的依赖包不会被删除。 这时我们就需要利用这个minimize-manual命令,先将依赖包标记为自动安装,然后再删除meta package, 最后通过autoremove就能把所有依赖包都删除了。