关于dnf命令的备忘录

首先,DNF是什么?

DNF是YUM的继任者,是一个软件包管理工具。
在CentOS 8中,默认采用的是DNF作为软件包管理工具,但是通过查看网上的文章,我感觉YUM仍然很常见。
我个人基本上是脑袋一片空白地使用DNF命令。

确认版本

dnf --version
Failed to set locale, defaulting to C.UTF-8
4.2.23
  Installed: dnf-0:4.2.23-4.el8.noarch at Mon May 31 12:54:12 2021
  Built    : CentOS Buildsys <bugs@centos.org> at Tue Aug  4 18:52:03 2020

  Installed: rpm-0:4.14.3-4.el8.x86_64 at Mon May 31 12:53:45 2021
  Built    : CentOS Buildsys <bugs@centos.org> at Tue J

与DNF相关的文件集合

以下是对上述内容的中文本地化改写:

– /var/cache/dnf:缓存文件
– /etc/dnf/dnf.conf:配置文件
– /etc/yum.repos.d/:存放软件源文件的目录。

显示存储库列表的方法(–all)

dnf repolist --all
Failed to set locale, defaulting to C.UTF-8
repo id                            repo name                            status
appstream                          CentOS Linux 8 - AppStream           enabled
appstream-source                   CentOS Linux 8 - AppStream - Source  disabled
baseos                             CentOS Linux 8 - BaseOS              enabled
baseos-source                      CentOS Linux 8 - BaseOS - Source     disabled
cr                                 CentOS Linux 8 - ContinuousRelease   disabled
debuginfo                          CentOS Linux 8 - Debuginfo           disabled
devel                              CentOS Linux 8 - Devel WARNING! FOR  disabled
epel                               Extra Packages for Enterprise Linux  enabled
epel-debuginfo                     Extra Packages for Enterprise Linux  disabled
epel-modular                       Extra Packages for Enterprise Linux  enabled
~~

虽然几乎完全不能使用并且没有使用过,但我也不知道它是什么存储库。

显示有效存储库的方法 (–enabled)。

$dnf repolist
Failed to set locale, defaulting to C.UTF-8
repo id                    repo name
appstream                  CentOS Linux 8 - AppStream
baseos                     CentOS Linux 8 - BaseOS
epel                       Extra Packages for Enterprise Linux 8 - x86_64
epel-modular               Extra Packages for Enterprise Linux Modular 8 - x86_64
extras                     CentOS Linux 8 - Extras
mysql-connectors-community MySQL Connectors Community
mysql-tools-community      MySQL Tools Community
mysql80-community          MySQL 8.0 Community Server
remi-modular               Remi's Modular repository for Enterprise Linux 8 - x86_64
remi-safe                  Safe Remi's RPM repository for Enterprise Linux 8 - x86_64


只有总体的10%左右被使用了,嗯、、

显示无效的仓库的方法(–disabled)。

$ dnf repolist --disabled
Failed to set locale, defaulting to C.UTF-8
repo id                            repo name
appstream-source                   CentOS Linux 8 - AppStream - Source
baseos-source                      CentOS Linux 8 - BaseOS - Source
cr                                 CentOS Linux 8 - ContinuousRelease
debuginfo                          CentOS Linux 8 - Debuginfo
devel                              CentOS Linux 8 - Devel WARNING! FOR BUILDROOT USE ONLY!
epel-debuginfo                     Extra Packages for Enterprise Linux 8 - x86_64 - Debug
epel-modular-debuginfo             Extra Packages for Enterprise Linux Modular 8 - x86_64 - Debug
epel-modular-source                Extra Packages for Enterprise Linux Modular 8 - x86_64 - Source
epel-playground                    Extra Packages for Enterprise Linux 8 - Playground - x86_64
epel-playground-debuginfo          Extra Packages for Enterprise Linux 8 - Playground - x86_64 - Debug
epel-playground-source             Extra Packages for Enterprise Linux 8 - Playground - x86_64 - Source
epel-source                        Extra Packages for Enterprise Linux 8 - x86_64 - Source
epel-testing                       Extra Packages for Enterprise Linux 8 - Testing - x86_64
epel-testing-debuginfo             Extra Packages for Enterprise Linux 8 - Testing - x86_64 - Debug
epel-testing-modular               Extra Packages for Enterprise Linux Modular 8 - Testing - x86_64
epel-testing-modular-debuginfo     Extra Packages for Enterprise Linux Modular 8 - Testing - x86_64 - Debug
epel-testing-modular-source        Extra Packages for Enterprise Linux Modular 8 - Testing - x86_64 - Source
epel-testing-source                Extra Packages for Enterprise Linux 8 - Testing - x86_64 - Source
extras-source                      CentOS Linux 8 - Extras - Source
fasttrack                          CentOS Linux 8 - FastTrack
ha                                 CentOS Linux 8 - HighAvailability
media-appstream                    CentOS Linux 8 - Media - AppStream
media-baseos                       CentOS Linux 8 - Media - BaseOS
mysql-cluster-7.5-community        MySQL Cluster 7.5 Community
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - Source
mysql-cluster-7.6-community        MySQL Cluster 7.6 Community
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - Source
mysql-cluster-8.0-community        MySQL Cluster 8.0 Community
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - Source
mysql-connectors-community-source  MySQL Connectors Community - Source
mysql-tools-community-source       MySQL Tools Community - Source
mysql-tools-preview                MySQL Tools Preview
mysql-tools-preview-source         MySQL Tools Preview - Source
mysql55-community                  MySQL 5.5 Community Server
mysql55-community-source           MySQL 5.5 Community Server - Source
mysql56-community                  MySQL 5.6 Community Server
mysql56-community-source           MySQL 5.6 Community Server - Source
mysql57-community                  MySQL 5.7 Community Server
mysql57-community-source           MySQL 5.7 Community Server - Source
mysql80-community-source           MySQL 8.0 Community Server - Source
plus                               CentOS Linux 8 - Plus
plus-source                        CentOS Linux 8 - Plus - Source
powertools                         CentOS Linux 8 - PowerTools
remi                               Remi's RPM repository for Enterprise Linux 8 - x86_64
remi-debuginfo                     Remi's RPM repository for Enterprise Linux 8 - x86_64 - debuginfo
remi-modular-test                  Remi's Modular testing repository for Enterprise Linux 8 - x86_64
remi-safe-debuginfo                Remi's RPM repository for Enterprise Linux 8 - x86_64 - debuginfo
remi-test                          Remi's test RPM repository for Enterprise Linux 8 - x86_64
remi-test-debuginfo                Remi's test RPM repository for Enterprise Linux 8 - x86_64 - debugin

有很多未使用的库啊。我使用的是MySQL 8版本,所以其他版本可能没有用。

确认DNF历史记录

$ dnf history
Failed to set locale, defaulting to C.UTF-8
ID     | Command line              | Date and time    | Action(s)      | Altered
--------------------------------------------------------------------------------
    18 | install telnet            | 2021-06-08 22:43 | Install        |    1   
    17 | install postfix           | 2021-06-08 21:55 | Install        |    1   
    16 | -y install langpacks-ja   | 2021-06-07 00:46 | Install        |    1   
    15 | --enablerepo=remi install | 2021-06-04 00:10 | Install        |   37   
    14 | install php-pdo php-json  | 2021-06-02 20:01 | Upgrade        |   15   
    13 | install wget              | 2021-06-02 19:48 | Install        |    1   
    12 | -y install mysql-communit | 2021-06-02 00:16 | I, O           |   14   
    11 | localinstall http://dev.m | 2021-06-02 00:08 | Install        |    1   
    10 | update                    | 2021-06-01 21:48 | Upgrade        |    2   
     9 | install -y lsof           | 2021-06-01 19:54 | Install        |    1   
     8 | update                    | 2021-05-31 21:52 | I, U           |  323 EE
     7 | --enablerepo=remi install | 2021-05-31 19:50 | Install        |   27 EE
     6 | install php-bcmath        | 2021-05-31 19:28 | Install        |    1   
     5 | module install php:remi-8 | 2021-05-31 19:21 | I, U           |   44   
     4 | install https://rpms.remi | 2021-05-31 19:16 | I, O, U        |    7   
     3 | -y install expect httpd-d | 2021-05-31 19:08 | I, U           |   59   
     2 | -y update                 | 2020-02-04 13:32 | I, U           |   44 EE
     1 |                           | 2020-02-04 13:28 | Install        |  620 EE


你安装了上一次的telnet吧。

输出详细信息

查询dnf历史信息ID。

让我们看一下上次安装的telnet的详细信息。因为ID是18,所以我们使用dnf history info 18来确认。

$ dnf history info 18
Failed to set locale, defaulting to C.UTF-8
Transaction ID : 18
Begin time     : Tue Jun  8 22:43:10 2021
Begin rpmdb    : 780:42e1a04c8966d87ca68cbae189750dbc18c24de4
End time       : Tue Jun  8 22:43:11 2021 (1 seconds)
End rpmdb      : 781:d69f533e4d9e377771617d639ef62030d5cd301d
User           :  <m1>
Return-Code    : Success
Releasever     : 8
Command Line   : install telnet
Comment        : 
Packages Altered:
    Install telnet-1:0.17-76.el8.x86_64 @appstream

您可以查看telnet安装信息的详细情况。

清除缓存

dnf clean all

总之,就是这样。