什么是自动安装?

如果你使用apt命令在终端中安装软件包,你将看到各种输出。
当你注意这些输出的时候,会看到一些提示。

1
package_name set to manually installed

你有没有想过这条消息是什么意思,为什么你没有在所有包上看到它?让我在本篇中分享一些细节。

那么从最常见的场景开始:复制文件和复制目录。

理解

当你尝试安装已安装的库或开发包时,你会看到这个输出。此依赖包是与另一个包一起自动安装的。如果删除了主包,则使用 apt autoremove 命令删除依赖包。

但是由于你试图显式安装依赖包,你的 Debian 系统认为你需要这个包独立于主包。因此,该软件包被标记为手动安装,不会被自动删除。

不是很清楚,对吧?以 在 Debian 上安装 inxi 为例。

由于主 inxi 包依赖于许多其他包,因此这些包会自动安装。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$ sudo apt install inxi
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
bind9-dnsutils bind9-host bind9-libs dnsutils file hddtemp libdrm-amdgpu1 libdrm-common libdrm-intel1
libdrm-nouveau2 libdrm-radeon1 libdrm2 libfontenc1 libfstrm0 libgl1 libgl1-mesa-dri libglapi-mesa libglew2.1
libglu1-mesa libglvnd0 libglx-mesa0 libglx0 libice6 libicu67 libllvm11 liblmdb0 libmagic-mgc libmagic1 libmaxminddb0
libpci3 libpciaccess0 libprotobuf-c1 libsensors-config libsensors5 libsm6 libusb-1.0-0 libuv1 libvulkan1
libwayland-client0 libx11-xcb1 libxaw7 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-randr0
libxcb-shape0 libxcb-shm0 libxcb-sync1 libxcb-xfixes0 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxft2
libxi6 libxinerama1 libxkbfile1 libxml2 libxmu6 libxrandr2 libxrender1 libxshmfence1 libxt6 libxtst6 libxv1
libxxf86dga1 libxxf86vm1 libz3-4 lm-sensors mesa-utils mesa-vulkan-drivers pci.ids pciutils tree usbutils x11-common
x11-utils x11-xserver-utils
Suggested packages:
libcpanel-json-xs-perl | libjson-xs-perl libxml-dumper-perl glew-utils mmdb-bin fancontrol read-edid i2c-tools
nickle cairo-5c xorg-docs-core
The following NEW packages will be installed:
bind9-dnsutils bind9-host bind9-libs dnsutils file hddtemp inxi libdrm-amdgpu1 libdrm-common libdrm-intel1
libdrm-nouveau2 libdrm-radeon1 libdrm2 libfontenc1 libfstrm0 libgl1 libgl1-mesa-dri libglapi-mesa libglew2.1
libglu1-mesa libglvnd0 libglx-mesa0 libglx0 libice6 libicu67 libllvm11 liblmdb0 libmagic-mgc libmagic1 libmaxminddb0
libpci3 libpciaccess0 libprotobuf-c1 libsensors-config libsensors5 libsm6 libusb-1.0-0 libuv1 libvulkan1
libwayland-client0 libx11-xcb1 libxaw7 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-randr0
libxcb-shape0 libxcb-shm0 libxcb-sync1 libxcb-xfixes0 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxft2
libxi6 libxinerama1 libxkbfile1 libxml2 libxmu6 libxrandr2 libxrender1 libxshmfence1 libxt6 libxtst6 libxv1
libxxf86dga1 libxxf86vm1 libz3-4 lm-sensors mesa-utils mesa-vulkan-drivers pci.ids pciutils tree usbutils x11-common
x11-utils x11-xserver-utils
0 upgraded, 80 newly installed, 0 to remove and 0 not upgraded.
Need to get 56.2 MB of archives.
After this operation, 226 MB of additional disk space will be used.
Do you want to continue? [Y/n]

比如我们检查第一个新安装的 bind9-dnsutils,会发现它被标记为“自动”。

这表明这些软件包是跟着 inxi 自动安装的,当 inxi 被卸载时,它们会被 apt autoremove 命令自动删除。

1
2
3
4
5
$ apt list --installed | grep bind9-dnsutils

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

bind9-dnsutils/stable,stable-security,now 1:9.16.27-1~deb11u1 amd64 [installed,automatic]

假设你出于某种原因考虑安装 bind9-dnsutils,如果运行 apt install 命令,系统会告诉你该软件包已安装。

同时,它将标记从自动更改为手动,因为系统认为在尝试手动安装表明需要此包。

1
2
3
4
5
6
7
8
9
10
11
12
13
$ sudo apt install bind9-dnsutils
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
bind9-dnsutils is already the newest version (1:9.16.27-1~deb11u1).
bind9-dnsutils set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

$ apt list --installed | grep bind9-dnsutils

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

bind9-dnsutils/stable,stable-security,now 1:9.16.27-1~deb11u1 amd64 [installed]

现在,删除 inxi 并运行 autoremove 命令。你可以看到 bind9-dnsutils 不在要删除的软件包列表中,并且它仍然在系统上面。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ sudo apt remove inxi
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
dnsutils file hddtemp libdrm-amdgpu1 libdrm-common libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libdrm2 libfontenc1
libgl1 libgl1-mesa-dri libglapi-mesa libglew2.1 libglu1-mesa libglvnd0 libglx-mesa0 libglx0 libice6 libllvm11
libmagic-mgc libmagic1 libpci3 libpciaccess0 libsensors-config libsensors5 libsm6 libusb-1.0-0 libvulkan1
libwayland-client0 libx11-xcb1 libxaw7 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-randr0
libxcb-shape0 libxcb-shm0 libxcb-sync1 libxcb-xfixes0 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxft2
libxi6 libxinerama1 libxkbfile1 libxmu6 libxrandr2 libxrender1 libxshmfence1 libxt6 libxtst6 libxv1 libxxf86dga1
libxxf86vm1 libz3-4 lm-sensors mesa-utils mesa-vulkan-drivers pci.ids pciutils tree usbutils x11-common x11-utils
x11-xserver-utils
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
inxi
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 995 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 26557 files and directories currently installed.)
Removing inxi (3.3.01-1-1) ...

$ apt list --installed | grep bind9-dnsutils

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

bind9-dnsutils/stable,stable-security,now 1:9.16.27-1~deb11u1 amd64 [installed]

将包设置为自动

1
2
3
4
5
6
7
8
$ sudo apt-mark auto bind9-dnsutils
bind9-dnsutils set to automatically installed.

$ apt list --installed | grep bind9-dnsutils

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

bind9-dnsutils/stable,stable-security,now 1:9.16.27-1~deb11u1 amd64 [installed,automatic]

这不是一个需要注意的错误,也不会中断你任何在系统中的工作。

但是,了解这些小事会增加你的知识。