在 apt 中,如何将包从直接包移动到传递包?

在 apt 中,如何将包从直接包移动到传递包?

我正在寻找一个命令:

  • 如果该包不是另一个安装包的过渡包,则删除/清除该包
  • 如果直接安装的包是另一个安装包的传递包,则将其声明为传递安装

我该怎么做呢?

答案1

您可以使用apt-mark将包设置为automatically installed

例子:

$ sudo apt install php8.1-cli
$ apt search php8.1-cli
php8.1-cli/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.14 amd64 [installed]
$ sudo apt install php
$ apt search php8.1-cli
php8.1-cli/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.14 amd64 [installed]
$ sudo apt-mark auto php8.1-cli
php8.1-cli set to automatically installed.
$ apt search php8.1-cli
php8.1-cli/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.14 amd64 [installed,automatic]
$ sudo apt remove php
The following packages were automatically installed and are no longer required:
  apache2 apache2-bin apache2-data apache2-utils bzip2 file libapache2-mod-php8.1 libapr1
  libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libargon2-1 libbrotli1 libbsd0 libcurl4
  libedit2 libexpat1 libgdbm-compat4 libgdbm6 libicu70 libjansson4 libldap-2.5-0 libldap-common
  liblua5.3-0 libmagic-mgc libmagic1 libmd0 libnghttp2-14 libperl5.34 libpsl5 librtmp1
  libsasl2-2 libsasl2-modules libsasl2-modules-db libsodium23 libsqlite3-0 libssh-4 libxml2
  mailcap media-types mime-support netbase perl perl-modules-5.34 php-common php8.1 php8.1-cli
  php8.1-common php8.1-opcache php8.1-readline publicsuffix ssl-cert tzdata ucf xz-utils
Use 'apt autoremove' to remove them.

我首先安装了php8.1-cli,它是该软件包的依赖项php。它显示为[installed]。运行后,apt-mark auto php8.1-cli它被标记为[installed,automatic]。当我现在卸载该php软件包时,它被列为,并将与 以及所有其他软件包一起automatically installed被删除。apt autoremove

相关内容