“Linux dnf安装软件”的版本间的差异

来自CloudWiki
跳转至: 导航搜索
 
(未显示同一用户的3个中间版本)
第12行: 第12行:
 
# 安装dnf包
 
# 安装dnf包
 
yum install dnf</nowiki>
 
yum install dnf</nowiki>
 +
 +
==常用命令==
 +
===查看 DNF 包管理器版本===
 +
 +
用处:该命令用于查看安装在您系统中的 DNF 包管理器的版本
 +
 +
dnf --version
 +
 +
<nowiki>4.7.0
 +
  Installed: dnf-0:4.7.0-4.el8.noarch at Fri 11 Feb 2022 09:53:15 AM GMT
 +
  Built    : CentOS Buildsys <bugs@centos.org> at Fri 17 Sep 2021 07:06:14 PM GMT
 +
 +
  Installed: rpm-0:4.14.3-19.el8.x86_64 at Fri 11 Feb 2022 09:52:41 AM GMT
 +
  Built    : CentOS Buildsys <bugs@centos.org> at Fri 15 Oct 2021 05:46:55 PM GMT</nowiki>
 +
 +
===查看系统中可用的 DNF 软件库===
 +
 +
用处:该命令用于显示系统中可用的 DNF 软件库
 +
 +
dnf repolist
 +
 +
<nowiki>
 +
repo id                                        repo name
 +
AppStream                                      CentOS-8.5.2111 - AppStream - mirrors.aliyun.com
 +
base                                            CentOS-8.5.2111 - Base - mirrors.aliyun.com
 +
epel-archive                                    Extra Packages for Enterprise Linux 8 - x86_64
 +
extras                                          CentOS-8.5.2111 - Extras - mirrors.aliyun.com</nowiki>
 +
 +
 +
 +
===查看系统中可用和不可用的所有的 DNF 软件库===
 +
 +
用处:该命令用于显示系统中可用和不可用的所有的 DNF 软件库
 +
 +
dnf repolist all
 +
 +
<nowiki>
 +
repo id                                      repo name                                                                    status
 +
AppStream                                    CentOS-8.5.2111 - AppStream - mirrors.aliyun.com                              enabled
 +
PowerTools                                  CentOS-8.5.2111 - PowerTools - mirrors.aliyun.com                            disabled
 +
base                                        CentOS-8.5.2111 - Base - mirrors.aliyun.com                                  enabled
 +
centosplus                                  CentOS-8.5.2111 - Plus - mirrors.aliyun.com                                  disabled
 +
epel-archive                                Extra Packages for Enterprise Linux 8 - x86_64                                enabled
 +
epel-archive-debuginfo                      Extra Packages for Enterprise Linux 8 - x86_64 - Debug                        disabled
 +
epel-archive-source                          Extra Packages for Enterprise Linux 8 - x86_64 - Source                      disabled
 +
extras                                      CentOS-8.5.2111 - Extras - mirrors.aliyun.com                                enabled
 +
[root@ecs-d01d ~]# </nowiki>
 +
 +
===列出所有 RPM 包===
 +
 +
用处:该命令用于列出用户系统上的所有来自软件库的可用软件包和所有已经安装在系统上的软件包
 +
 +
dnf list
 +
 +
<nowiki>
 +
zstd.x86_64                                                1.4.4-1.el8                                                AppStream 
 +
zstd.x86_64                                                1.4.4-1.el8                                                epel-archive
 +
zvbi.x86_64                                                0.2.35-9.el8                                                epel-archive
 +
zvbi-devel.x86_64                                          0.2.35-9.el8                                                epel-archive
 +
zvbi-fonts.noarch                                          0.2.35-9.el8                                                epel-archive
 +
zziplib.i686                                              0.13.68-9.el8                                              AppStream 
 +
zziplib.x86_64                                            0.13.68-9.el8                                              AppStream 
 +
zziplib-utils.x86_64                                      0.13.68-9.el8                                              AppStream </nowiki>
 +
 +
===列出所有安装了的 RPM 包===
 +
 +
用处:该命令用于列出所有安装了的 RPM 包
 +
 +
dnf list installed
 +
 +
<nowiki>
 +
xfsprogs.x86_64                                            5.0.0-9.el8                                                  @BaseOS 
 +
xkeyboard-config.noarch                                    2.28-1.el8                                                    @AppStream
 +
xz.x86_64                                                  5.2.4-3.el8                                                  @anaconda
 +
xz-libs.x86_64                                            5.2.4-3.el8                                                  @anaconda
 +
yum.noarch                                                4.7.0-4.el8                                                  @BaseOS 
 +
zlib.x86_64                                                1.2.11-17.el8                                                @BaseOS </nowiki>
 +
 +
===列出所有可供安装的 RPM 包===
 +
 +
用处:该命令用于列出来自所有可用软件库的可供安装的软件包
 +
 +
dnf list available
 +
 +
<nowiki>
 +
zstd.x86_64                                                1.4.4-1.el8                                                AppStream 
 +
zstd.x86_64                                                1.4.4-1.el8                                                epel-archive
 +
zvbi.x86_64                                                0.2.35-9.el8                                                epel-archive
 +
zvbi-devel.x86_64                                          0.2.35-9.el8                                                epel-archive
 +
zvbi-fonts.noarch                                          0.2.35-9.el8                                                epel-archive
 +
zziplib.i686                                              0.13.68-9.el8                                              AppStream 
 +
zziplib.x86_64                                            0.13.68-9.el8                                              AppStream 
 +
zziplib-utils.x86_64                                      0.13.68-9.el8                                              AppStream </nowiki>
 +
 +
===搜索软件库中的 RPM 包===
 +
 +
用处:当你不知道你想要安装的软件的准确名称时,你可以用该命令来搜索软件包。你需要在”search”参数后面键入软件的部分名称来搜索。(在本例中我们使用”nano”)
 +
 +
dnf search nano
 +
 +
<nowiki>
 +
Last metadata expiration check: 15:33:48 ago on Sat 28 May 2022 08:29:54 PM CST.
 +
=================================================== Name Exactly Matched: nano ====================================================
 +
nano.x86_64 : A small text editor
 +
====================================================== Summary Matched: nano ======================================================
 +
spacewalk-usix.noarch : Spacewalk server and client nano six library</nowiki>
 +
 +
===查找某一文件的提供者===
 +
 +
用处:当你想要查看是哪个软件包提供了系统中的某一文件时,你可以使用这条命令。(在本例中,我们将查找”/bin/bash”这个文件的提供者)
 +
 +
dnf provides /bin/bash
 +
 +
<nowiki>
 +
Last metadata expiration check: 15:34:59 ago on Sat 28 May 2022 08:29:54 PM CST.
 +
bash-4.4.20-2.el8.x86_64 : The GNU Bourne Again shell
 +
Repo        : @System
 +
Matched from:
 +
Provide    : /bin/bash
 +
 +
bash-4.4.20-2.el8.x86_64 : The GNU Bourne Again shell
 +
Repo        : base
 +
Matched from:
 +
Provide    : /bin/bash</nowiki>
 +
 +
===查看软件包详情===
 +
 +
用处:当你想在安装某一个软件包之前查看它的详细信息时,这条命令可以帮到你。(在本例中,我们将查看”nano”这一软件包的详细信息)
 +
 +
dnf info nano
 +
 +
<nowiki>
 +
Last metadata expiration check: 0:03:40 ago on Sun 29 May 2022 12:15:06 PM CST.
 +
Available Packages
 +
Name        : nano
 +
Version      : 2.9.8
 +
Release      : 1.el8
 +
Architecture : x86_64
 +
Size        : 581 k
 +
Source      : nano-2.9.8-1.el8.src.rpm
 +
Repository  : base
 +
Summary      : A small text editor
 +
URL          : https://www.nano-editor.org
 +
License      : GPLv3+
 +
Description  : GNU nano is a small and friendly text editor.</nowiki>
 +
 +
===安装软件包(重点)===
 +
 +
用处:使用该命令,系统将会自动安装对应的软件及其所需的所有依赖(在本例中,我们将用该命令安装nano软件)
 +
 +
dnf install nano -y
 +
 +
<nowiki>Last metadata expiration check: 0:04:50 ago on Sun 29 May 2022 12:15:06 PM CST.
 +
Dependencies resolved.
 +
===================================================================================================================================
 +
Package                    Architecture                  Version                              Repository                  Size
 +
===================================================================================================================================
 +
Installing:
 +
nano                        x86_64                        2.9.8-1.el8                          base                        581 k
 +
 +
Transaction Summary
 +
===================================================================================================================================
 +
Install  1 Package</nowiki>
 +
 +
===升级软件包===
 +
 +
用处:该命令用于升级制定软件包(在本例中,我们将用命令升级”systemd”这一软件包)
 +
 +
dnf update systemd
 +
 +
<nowiki>
 +
Last metadata expiration check: 3:34:30 ago on Sun 29 May 2022 12:15:06 PM CST.
 +
Dependencies resolved.
 +
Nothing to do.
 +
Complete!</nowiki>
 +
 +
===检查系统软件包的更新===
 +
 +
用处:该命令用于检查系统中所有软件包的更新
 +
 +
dnf check-update
 +
 +
<nowiki>
 +
centos-gpg-keys.noarch                                          1:8-3.el8                                                base   
 +
initscripts.x86_64                                              10.00.15-1.el8                                          base   
 +
Obsoleting Packages
 +
centos-linux-release.noarch                                      8.5-1.2111.el8                                          base   
 +
    centos-release.x86_64                                        8.1-1.1911.0.8.el8                                      @anaconda
 +
centos-linux-release.noarch                                      8.5-1.2111.el8                                          base   
 +
    centos-repos.x86_64                                          8.1-1.1911.0.8.el8                                      @anaconda</nowiki>
 +
 +
===升级所有系统软件包===
 +
 +
用处:该命令用于升级系统中所有有可用升级的软件包
 +
 +
dnf update 或 # dnf upgrade
 +
 +
<nowiki>
 +
Last metadata expiration check: 3:37:42 ago on Sun 29 May 2022 12:15:06 PM CST.
 +
Dependencies resolved.
 +
===================================================================================================================================
 +
Package                                Architecture              Version                          Repository              Size
 +
===================================================================================================================================
 +
Installing:
 +
centos-linux-release                    noarch                    8.5-1.2111.el8                    base                    22 k
 +
    replacing  centos-release.x86_64 8.1-1.1911.0.8.el8
 +
    replacing  centos-repos.x86_64 8.1-1.1911.0.8.el8
 +
Upgrading:
 +
centos-gpg-keys                        noarch                    1:8-3.el8                        base                    12 k
 +
initscripts                            x86_64                    10.00.15-1.el8                    base                    339 k
 +
Installing dependencies:
 +
centos-linux-repos                      noarch                    8-3.el8                          base                    20 k
 +
 +
Transaction Summary
 +
===================================================================================================================================
 +
Install  2 Packages
 +
Upgrade  2 Packages</nowiki>
 +
 +
===删除软件包===
 +
 +
用处:删除系统中指定的软件包(在本例中我们将使用命令删除”nano”这一软件包)
 +
 +
dnf remove nano 或 # dnf erase nano
 +
 +
<nowiki>
 +
Repository extras is listed more than once in the configuration
 +
Dependencies resolved.
 +
===================================================================================================================================
 +
Package                    Architecture                  Version                              Repository                    Size
 +
===================================================================================================================================
 +
Removing:
 +
nano                        x86_64                        2.9.8-1.el8                          @base                        2.2 M
 +
 +
Transaction Summary
 +
===================================================================================================================================
 +
Remove  1 Package</nowiki>
 +
 +
===删除无用孤立的软件包===
 +
 +
用处:当没有软件再依赖它们时,某一些用于解决特定软件依赖的软件包将会变得没有存在的意义,该命令就是用来自动移除这些没用的孤立软件包。
 +
 +
dnf autoremove
 +
 +
<nowiki>
 +
Repository extras is listed more than once in the configuration
 +
CentOS Linux 8 - AppStream                                                                        104  B/s |  38  B    00:00   
 +
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist</nowiki>
 +
 +
===删除缓存的无用软件包===
 +
 +
用处:在使用 DNF 的过程中,会因为各种原因在系统中残留各种过时的文件和未完成的编译工程。我们可以使用该命令来删除这些没用的垃圾文件。
 +
 +
dnf clean all
 +
 +
<nowiki>
 +
Repository extras is listed more than once in the configuration
 +
28 files removed</nowiki>
 +
 +
 +
===获取有关某条命令的使用帮助===
 +
 +
用处:该命令用于获取有关某条命令的使用帮助(包括可用于该命令的参数和该命令的用途说明)(本例中我们将使用命令获取有关命令”clean”的使用帮助)
 +
 +
dnf help clean
 +
 +
<nowiki>
 +
Repository extras is listed more than once in the configuration
 +
28 files removed
 +
[root@ecs-d01d flask_test]# dnf help clean
 +
Repository extras is listed more than once in the configuration
 +
usage: dnf clean [-c [config file]] [-q] [-v] [--version]
 +
                [--installroot [path]] [--nodocs] [--noplugins]
 +
                [--enableplugin [plugin]] [--disableplugin [plugin]]
 +
                [--releasever RELEASEVER] [--setopt SETOPTS] [--skip-broken]</nowiki>
 +
 +
===查看所有的 DNF 命令及其用途===
 +
 +
用处:该命令用于列出所有的 DNF 命令及其用途
 +
 +
dnf help
 +
 +
<nowiki>
 +
Repository extras is listed more than once in the configuration
 +
usage: dnf [options] COMMAND
 +
 +
List of Main Commands:
 +
 +
alias                    List or create command aliases
 +
autoremove                remove all unneeded packages that were originally installed as dependencies
 +
check                    check for problems in the packagedb
 +
check-update              check for available package upgrades
 +
clean                    remove cached data
 +
deplist                  [deprecated, use repoquery --deplist] List package's dependencies and what packages provide them
 +
distro-sync              synchronize installed packages to the latest available versions
 +
downgrade                Downgrade a package
 +
group                    display, or use, the groups information
 +
help                      display a helpful usage message
 +
history                  display, or use, the transaction history
 +
info                      display details about a package or group of packages</nowiki>
 +
 +
===查看 DNF 命令的执行历史===
 +
 +
用处:您可以使用该命令来查看您系统上 DNF 命令的执行历史。通过这个手段您可以知道在自您使用 DNF 开始有什么软件被安装和卸载。
 +
 +
dnf history
 +
 +
<nowiki>
 +
Repository extras is listed more than once in the configuration
 +
ID    | Command line                                                                | Date and time    | Action(s)      | Altered
 +
-----------------------------------------------------------------------------------------------------------------------------------
 +
    11 | remove nano                                                                  | 2022-05-29 15:54 | Removed        |    1 
 +
    10 | update                                                                      | 2022-05-29 15:52 | I, O, U        |    6 EE
 +
    9 | install nano -y                                                              | 2022-05-29 12:19 | Install        |    1 
 +
    8 | install python36-devel                                                      | 2022-05-26 09:32 | Install        |    6  <
 +
    7 | update -y -x centos-release* -x centos-repos -x centos-gpg-keys -x initscrip | 2022-02-11 17:51 | I, U          |  333 >E
 +
    6 | update -y rng-tools                                                          | 2022-02-11 17:42 | Upgrade        |    1 
 +
    5 | install -y sos                                                              | 2022-02-11 17:42 | Install        |    4 
 +
    4 | install -y cloud-utils-growpart                                              | 2022-02-11 17:42 | Install        |    1 
 +
    3 | install -y iftop                                                            | 2022-02-11 17:42 | Install        |    1 
 +
    2 | install -y epel-release                                                      | 2022-02-11 17:40 | Install        |    1 
 +
    1 |                                                                              | 2022-02-11 17:34 | Install        |  440 EE</nowiki>
 +
 +
===查看所有的软件包组===
 +
 +
用处:该命令用于列出所有的软件包组
 +
 +
dnf grouplist
 +
 +
<nowiki>Repository extras is listed more than once in the configuration
 +
CentOS Linux 8 - AppStream                                                                          86  B/s |  38  B    00:00   
 +
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist</nowiki>
 +
 +
===安装一个软件包组===
 +
 +
用处:该命令用于安装一个软件包组(本例中,我们将用命令安装”Educational Software”这个软件包组)
 +
 +
dnf groupinstall ‘Educational Software’
 +
 +
 +
 +
===升级一个软件包组中的软件包===
 +
 +
用处:该命令用于升级一个软件包组中的软件包(本例中,我们将用命令升级”Educational Software”这个软件包组中的软件)
 +
 +
dnf groupupdate ‘Educational Software’
 +
 +
 +
 +
===删除一个软件包组===
 +
 +
用处:该命令用于删除一个软件包组(本例中,我们将用命令删除”Educational Software”这个软件包组)
 +
 +
dnf groupremove ‘Educational Software’
 +
 +
 +
 +
===从特定的软件包库安装特定的软件===
 +
 +
用处:该命令用于从特定的软件包库安装特定的软件(本例中我们将使用命令从软件包库 epel 中安装 phpmyadmin 软件包)
 +
 +
dnf –enablerepo=epel install phpmyadmin
 +
 +
===更新软件包到最新的稳定发行版===
 +
 +
用处:该命令可以通过所有可用的软件源将已经安装的所有软件包更新到最新的稳定发行版
 +
 +
dnf distro-sync
 +
 +
===重新安装特定软件包===
 +
 +
用处:该命令用于重新安装特定软件包(本例中,我们将使用命令重新安装”nano”这个软件包)
 +
 +
dnf reinstall nano
 +
 +
===回滚某个特定软件的版本===
 +
 +
用处:该命令用于降低特定软件包的版本(如果可能的话)(本例中,我们将使用命令降低”acpid”这个软件包的版本)
 +
 +
dnf downgrade acpid
 +
 +
样例输出:
 +
 +
<nowiki>Using metadata from Wed May 20 12:44:59 2015
 +
No match for available package: acpid-2.0.19-5.el7.x86_64
 +
Error: Nothing to do.</nowiki>
 +
 +
原作者注:在执行这条命令的时候, DNF 并没有按照我期望的那样降级指定的软件(“acpid”)。该问题已经上报。
 +
总结
 +
 +
==评价==
 +
DNF 包管理器作为 YUM 包管理器的升级替代品,它能自动完成更多的操作。但在我看来,正因如此,所以 DNF 包管理器不会太受那些经验老道的 Linux 系统管理者的欢迎。举例如下:
 +
 +
*在 DNF 中没有 –skip-broken 命令,并且没有替代命令供选择。
 +
*在 DNF 中没有判断哪个包提供了指定依赖的 resolvedep 命令。
 +
*在 DNF 中没有用来列出某个软件依赖包的 deplist 命令。
 +
*当你在 DNF 中排除了某个软件库,那么该操作将会影响到你之后所有的操作,不像在 YUM 下那样,你的排除操作只会咋升级和安装软件时才起作用。
  
  

2022年5月30日 (一) 13:53的最新版本

dnf简介

dnf是新一代的RPM软件包管理器,与yum包管理器相比,在用户体验、内存占用、依赖分析、运行速度等多方面得到了较好的提升。

dnf首次出现在Fedora18(注:中文名费多拉,Fedora对于用户而言,是一套功能完备、更新快速的免费操作系统)这个发行版中,在Fedora22发行版本中正式取代yum成为其默认的包管理器。

dnf未默认在RHEL或CentOS 7系统中安装,如果使用,可以单独安装

安装步骤

# 安装epel-release依赖
yum install epel-release
# 安装dnf包
yum install dnf

常用命令

查看 DNF 包管理器版本

用处:该命令用于查看安装在您系统中的 DNF 包管理器的版本

dnf --version

4.7.0
  Installed: dnf-0:4.7.0-4.el8.noarch at Fri 11 Feb 2022 09:53:15 AM GMT
  Built    : CentOS Buildsys <bugs@centos.org> at Fri 17 Sep 2021 07:06:14 PM GMT

  Installed: rpm-0:4.14.3-19.el8.x86_64 at Fri 11 Feb 2022 09:52:41 AM GMT
  Built    : CentOS Buildsys <bugs@centos.org> at Fri 15 Oct 2021 05:46:55 PM GMT

查看系统中可用的 DNF 软件库

用处:该命令用于显示系统中可用的 DNF 软件库

dnf repolist

repo id                                         repo name
AppStream                                       CentOS-8.5.2111 - AppStream - mirrors.aliyun.com
base                                            CentOS-8.5.2111 - Base - mirrors.aliyun.com
epel-archive                                    Extra Packages for Enterprise Linux 8 - x86_64
extras                                          CentOS-8.5.2111 - Extras - mirrors.aliyun.com


查看系统中可用和不可用的所有的 DNF 软件库

用处:该命令用于显示系统中可用和不可用的所有的 DNF 软件库

dnf repolist all

repo id                                      repo name                                                                     status
AppStream                                    CentOS-8.5.2111 - AppStream - mirrors.aliyun.com                              enabled
PowerTools                                   CentOS-8.5.2111 - PowerTools - mirrors.aliyun.com                             disabled
base                                         CentOS-8.5.2111 - Base - mirrors.aliyun.com                                   enabled
centosplus                                   CentOS-8.5.2111 - Plus - mirrors.aliyun.com                                   disabled
epel-archive                                 Extra Packages for Enterprise Linux 8 - x86_64                                enabled
epel-archive-debuginfo                       Extra Packages for Enterprise Linux 8 - x86_64 - Debug                        disabled
epel-archive-source                          Extra Packages for Enterprise Linux 8 - x86_64 - Source                       disabled
extras                                       CentOS-8.5.2111 - Extras - mirrors.aliyun.com                                 enabled
[root@ecs-d01d ~]# 

列出所有 RPM 包

用处:该命令用于列出用户系统上的所有来自软件库的可用软件包和所有已经安装在系统上的软件包

dnf list

zstd.x86_64                                                1.4.4-1.el8                                                 AppStream   
zstd.x86_64                                                1.4.4-1.el8                                                 epel-archive
zvbi.x86_64                                                0.2.35-9.el8                                                epel-archive
zvbi-devel.x86_64                                          0.2.35-9.el8                                                epel-archive
zvbi-fonts.noarch                                          0.2.35-9.el8                                                epel-archive
zziplib.i686                                               0.13.68-9.el8                                               AppStream   
zziplib.x86_64                                             0.13.68-9.el8                                               AppStream   
zziplib-utils.x86_64                                       0.13.68-9.el8                                               AppStream 

列出所有安装了的 RPM 包

用处:该命令用于列出所有安装了的 RPM 包

dnf list installed

xfsprogs.x86_64                                            5.0.0-9.el8                                                   @BaseOS   
xkeyboard-config.noarch                                    2.28-1.el8                                                    @AppStream
xz.x86_64                                                  5.2.4-3.el8                                                   @anaconda 
xz-libs.x86_64                                             5.2.4-3.el8                                                   @anaconda 
yum.noarch                                                 4.7.0-4.el8                                                   @BaseOS   
zlib.x86_64                                                1.2.11-17.el8                                                 @BaseOS 

列出所有可供安装的 RPM 包

用处:该命令用于列出来自所有可用软件库的可供安装的软件包

dnf list available

zstd.x86_64                                                1.4.4-1.el8                                                 AppStream   
zstd.x86_64                                                1.4.4-1.el8                                                 epel-archive
zvbi.x86_64                                                0.2.35-9.el8                                                epel-archive
zvbi-devel.x86_64                                          0.2.35-9.el8                                                epel-archive
zvbi-fonts.noarch                                          0.2.35-9.el8                                                epel-archive
zziplib.i686                                               0.13.68-9.el8                                               AppStream   
zziplib.x86_64                                             0.13.68-9.el8                                               AppStream   
zziplib-utils.x86_64                                       0.13.68-9.el8                                               AppStream 

搜索软件库中的 RPM 包

用处:当你不知道你想要安装的软件的准确名称时,你可以用该命令来搜索软件包。你需要在”search”参数后面键入软件的部分名称来搜索。(在本例中我们使用”nano”)

dnf search nano

Last metadata expiration check: 15:33:48 ago on Sat 28 May 2022 08:29:54 PM CST.
=================================================== Name Exactly Matched: nano ====================================================
nano.x86_64 : A small text editor
====================================================== Summary Matched: nano ======================================================
spacewalk-usix.noarch : Spacewalk server and client nano six library

查找某一文件的提供者

用处:当你想要查看是哪个软件包提供了系统中的某一文件时,你可以使用这条命令。(在本例中,我们将查找”/bin/bash”这个文件的提供者)

dnf provides /bin/bash

Last metadata expiration check: 15:34:59 ago on Sat 28 May 2022 08:29:54 PM CST.
bash-4.4.20-2.el8.x86_64 : The GNU Bourne Again shell
Repo        : @System
Matched from:
Provide    : /bin/bash

bash-4.4.20-2.el8.x86_64 : The GNU Bourne Again shell
Repo        : base
Matched from:
Provide    : /bin/bash

查看软件包详情

用处:当你想在安装某一个软件包之前查看它的详细信息时,这条命令可以帮到你。(在本例中,我们将查看”nano”这一软件包的详细信息)

dnf info nano

Last metadata expiration check: 0:03:40 ago on Sun 29 May 2022 12:15:06 PM CST.
Available Packages
Name         : nano
Version      : 2.9.8
Release      : 1.el8
Architecture : x86_64
Size         : 581 k
Source       : nano-2.9.8-1.el8.src.rpm
Repository   : base
Summary      : A small text editor
URL          : https://www.nano-editor.org
License      : GPLv3+
Description  : GNU nano is a small and friendly text editor.

安装软件包(重点)

用处:使用该命令,系统将会自动安装对应的软件及其所需的所有依赖(在本例中,我们将用该命令安装nano软件)

dnf install nano -y

Last metadata expiration check: 0:04:50 ago on Sun 29 May 2022 12:15:06 PM CST.
Dependencies resolved.
===================================================================================================================================
 Package                     Architecture                  Version                               Repository                   Size
===================================================================================================================================
Installing:
 nano                        x86_64                        2.9.8-1.el8                           base                        581 k

Transaction Summary
===================================================================================================================================
Install  1 Package

升级软件包

用处:该命令用于升级制定软件包(在本例中,我们将用命令升级”systemd”这一软件包)

dnf update systemd

Last metadata expiration check: 3:34:30 ago on Sun 29 May 2022 12:15:06 PM CST.
Dependencies resolved.
Nothing to do.
Complete!

检查系统软件包的更新

用处:该命令用于检查系统中所有软件包的更新

dnf check-update

centos-gpg-keys.noarch                                           1:8-3.el8                                                base     
initscripts.x86_64                                               10.00.15-1.el8                                           base     
Obsoleting Packages
centos-linux-release.noarch                                      8.5-1.2111.el8                                           base     
    centos-release.x86_64                                        8.1-1.1911.0.8.el8                                       @anaconda
centos-linux-release.noarch                                      8.5-1.2111.el8                                           base     
    centos-repos.x86_64                                          8.1-1.1911.0.8.el8                                       @anaconda

升级所有系统软件包

用处:该命令用于升级系统中所有有可用升级的软件包

dnf update 或 # dnf upgrade

Last metadata expiration check: 3:37:42 ago on Sun 29 May 2022 12:15:06 PM CST.
Dependencies resolved.
===================================================================================================================================
 Package                                 Architecture              Version                           Repository               Size
===================================================================================================================================
Installing:
 centos-linux-release                    noarch                    8.5-1.2111.el8                    base                     22 k
     replacing  centos-release.x86_64 8.1-1.1911.0.8.el8
     replacing  centos-repos.x86_64 8.1-1.1911.0.8.el8
Upgrading:
 centos-gpg-keys                         noarch                    1:8-3.el8                         base                     12 k
 initscripts                             x86_64                    10.00.15-1.el8                    base                    339 k
Installing dependencies:
 centos-linux-repos                      noarch                    8-3.el8                           base                     20 k

Transaction Summary
===================================================================================================================================
Install  2 Packages
Upgrade  2 Packages

删除软件包

用处:删除系统中指定的软件包(在本例中我们将使用命令删除”nano”这一软件包)

dnf remove nano 或 # dnf erase nano

Repository extras is listed more than once in the configuration
Dependencies resolved.
===================================================================================================================================
 Package                     Architecture                  Version                              Repository                    Size
===================================================================================================================================
Removing:
 nano                        x86_64                        2.9.8-1.el8                          @base                        2.2 M

Transaction Summary
===================================================================================================================================
Remove  1 Package

删除无用孤立的软件包

用处:当没有软件再依赖它们时,某一些用于解决特定软件依赖的软件包将会变得没有存在的意义,该命令就是用来自动移除这些没用的孤立软件包。

dnf autoremove

Repository extras is listed more than once in the configuration
CentOS Linux 8 - AppStream                                                                         104  B/s |  38  B     00:00    
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

删除缓存的无用软件包

用处:在使用 DNF 的过程中,会因为各种原因在系统中残留各种过时的文件和未完成的编译工程。我们可以使用该命令来删除这些没用的垃圾文件。

dnf clean all

Repository extras is listed more than once in the configuration
28 files removed


获取有关某条命令的使用帮助

用处:该命令用于获取有关某条命令的使用帮助(包括可用于该命令的参数和该命令的用途说明)(本例中我们将使用命令获取有关命令”clean”的使用帮助)

dnf help clean

Repository extras is listed more than once in the configuration
28 files removed
[root@ecs-d01d flask_test]# dnf help clean
Repository extras is listed more than once in the configuration
usage: dnf clean [-c [config file]] [-q] [-v] [--version]
                 [--installroot [path]] [--nodocs] [--noplugins]
                 [--enableplugin [plugin]] [--disableplugin [plugin]]
                 [--releasever RELEASEVER] [--setopt SETOPTS] [--skip-broken]

查看所有的 DNF 命令及其用途

用处:该命令用于列出所有的 DNF 命令及其用途

dnf help

Repository extras is listed more than once in the configuration
usage: dnf [options] COMMAND

List of Main Commands:

alias                     List or create command aliases
autoremove                remove all unneeded packages that were originally installed as dependencies
check                     check for problems in the packagedb
check-update              check for available package upgrades
clean                     remove cached data
deplist                   [deprecated, use repoquery --deplist] List package's dependencies and what packages provide them
distro-sync               synchronize installed packages to the latest available versions
downgrade                 Downgrade a package
group                     display, or use, the groups information
help                      display a helpful usage message
history                   display, or use, the transaction history
info                      display details about a package or group of packages

查看 DNF 命令的执行历史

用处:您可以使用该命令来查看您系统上 DNF 命令的执行历史。通过这个手段您可以知道在自您使用 DNF 开始有什么软件被安装和卸载。

dnf history

Repository extras is listed more than once in the configuration
ID     | Command line                                                                 | Date and time    | Action(s)      | Altered
-----------------------------------------------------------------------------------------------------------------------------------
    11 | remove nano                                                                  | 2022-05-29 15:54 | Removed        |    1   
    10 | update                                                                       | 2022-05-29 15:52 | I, O, U        |    6 EE
     9 | install nano -y                                                              | 2022-05-29 12:19 | Install        |    1   
     8 | install python36-devel                                                       | 2022-05-26 09:32 | Install        |    6  <
     7 | update -y -x centos-release* -x centos-repos -x centos-gpg-keys -x initscrip | 2022-02-11 17:51 | I, U           |  333 >E
     6 | update -y rng-tools                                                          | 2022-02-11 17:42 | Upgrade        |    1   
     5 | install -y sos                                                               | 2022-02-11 17:42 | Install        |    4   
     4 | install -y cloud-utils-growpart                                              | 2022-02-11 17:42 | Install        |    1   
     3 | install -y iftop                                                             | 2022-02-11 17:42 | Install        |    1   
     2 | install -y epel-release                                                      | 2022-02-11 17:40 | Install        |    1   
     1 |                                                                              | 2022-02-11 17:34 | Install        |  440 EE

查看所有的软件包组

用处:该命令用于列出所有的软件包组

dnf grouplist

Repository extras is listed more than once in the configuration
CentOS Linux 8 - AppStream                                                                          86  B/s |  38  B     00:00    
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

安装一个软件包组

用处:该命令用于安装一个软件包组(本例中,我们将用命令安装”Educational Software”这个软件包组)

dnf groupinstall ‘Educational Software’


升级一个软件包组中的软件包

用处:该命令用于升级一个软件包组中的软件包(本例中,我们将用命令升级”Educational Software”这个软件包组中的软件)

dnf groupupdate ‘Educational Software’


删除一个软件包组

用处:该命令用于删除一个软件包组(本例中,我们将用命令删除”Educational Software”这个软件包组)

dnf groupremove ‘Educational Software’


从特定的软件包库安装特定的软件

用处:该命令用于从特定的软件包库安装特定的软件(本例中我们将使用命令从软件包库 epel 中安装 phpmyadmin 软件包)

dnf –enablerepo=epel install phpmyadmin

更新软件包到最新的稳定发行版

用处:该命令可以通过所有可用的软件源将已经安装的所有软件包更新到最新的稳定发行版

dnf distro-sync

重新安装特定软件包

用处:该命令用于重新安装特定软件包(本例中,我们将使用命令重新安装”nano”这个软件包)

dnf reinstall nano

回滚某个特定软件的版本

用处:该命令用于降低特定软件包的版本(如果可能的话)(本例中,我们将使用命令降低”acpid”这个软件包的版本)

dnf downgrade acpid

样例输出:

Using metadata from Wed May 20 12:44:59 2015
No match for available package: acpid-2.0.19-5.el7.x86_64
Error: Nothing to do.

原作者注:在执行这条命令的时候, DNF 并没有按照我期望的那样降级指定的软件(“acpid”)。该问题已经上报。 总结

评价

DNF 包管理器作为 YUM 包管理器的升级替代品,它能自动完成更多的操作。但在我看来,正因如此,所以 DNF 包管理器不会太受那些经验老道的 Linux 系统管理者的欢迎。举例如下:

  • 在 DNF 中没有 –skip-broken 命令,并且没有替代命令供选择。
  • 在 DNF 中没有判断哪个包提供了指定依赖的 resolvedep 命令。
  • 在 DNF 中没有用来列出某个软件依赖包的 deplist 命令。
  • 当你在 DNF 中排除了某个软件库,那么该操作将会影响到你之后所有的操作,不像在 YUM 下那样,你的排除操作只会咋升级和安装软件时才起作用。


参考文档

https://cloud.tencent.com/developer/article/1923243

http://ipcmen.com/dnf