Linux系统之dnf包管理器的基本使用

江湖有缘
• 阅读 130

@TOC

一、dnf工具介绍

1. dnf工具简介

DNF(Dandified Yum)是Fedora Linux操作系统中的一个包管理器,它是基于Yum开发的。它的主要特点是快速、可靠、易用和优秀的用户体验。

2. dnf的功能

DNF提供了许多强大的功能和命令行工具,包括:

  • 安装和升级软件包:可以使用dnf install和dnf update命令来安装和升级软件包。

  • 查询和列出软件包:可以使用dnf search和dnf list命令来查询和列出软件包。

  • 删除软件包:可以使用dnf remove命令来删除已安装的软件包。

  • 清理系统:可以使用dnf clean命令来清理系统中的软件包缓存和元数据。

  • 版本管理:可以使用dnf history命令来查看软件包操作历史记录,并进行回滚或重做操作。

  • 软件包组管理:可以使用dnf group命令来安装、升级和删除软件包组。

  • 存储库管理:可以使用dnf repolist命令来列出系统中的存储库,并使用dnf config命令来配置存储库。

二、DNF的安装

1. 检查本地操作系统版本

检查本地操作系统版本

[root@jeven ~]# cat /etc/system-release
CentOS Linux release 7.6.1810 (Core) 

2. 安装epel

  • 配置epel,启动epel的yum仓库。
yum install epel-release -y
  • 或者使用阿里云的epel源
    wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

3. 检查本地yum仓库状态

检查本地yum仓库状态

[root@jeven ~]# yum repolist all |grep enable 
!base/7/x86_64        CentOS-7 - Base - mirrors.aliyun.com       enabled: 10,072
epel/x86_64           Extra Packages for Enterprise Linux 7 - x8 enabled: 13,753
!extras/7/x86_64      CentOS-7 - Extras - mirrors.aliyun.com     enabled:    515
!updates/7/x86_64     CentOS-7 - Updates - mirrors.aliyun.com    enabled:  5,053

4. 安装dnf包

使用yum安装dnf包

yum install dnf -y

Linux系统之dnf包管理器的基本使用

三、dnf的使用帮助

1. 查看dnf版本

查看dnf包管理器版本

[root@jeven ~]# dnf --version
4.0.9
  Installed: dnf-0:4.0.9.2-2.el7_9.noarch at Mon 03 Jul 2023 11:24:14 AM CST
  Built    : CentOS BuildSystem <http://bugs.centos.org> at Wed 07 Apr 2021 03:52:38 PM CST

  Installed: rpm-0:4.11.3-48.el7_9.x86_64 at Sat 24 Jun 2023 10:08:53 PM CST
  Built    : CentOS BuildSystem <http://bugs.centos.org> at Wed 24 Nov 2021 04:33:39 PM CST

2. 查看dnf命令的帮助信息

查看DNF在Linux的help帮助信息

[root@jeven ~]# dnf --help
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                   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
install                   install a package or packages on your system
list                      list a package or groups of packages
makecache                 generate the metadata cache
mark                      mark or unmark installed packages as installed by user.
module                    Interact with Modules.
provides                  find what package provides the given value
reinstall                 reinstall a package
remove                    remove a package or packages from your system
repolist                  display the configured software repositories
repoquery                 search for packages matching keyword
repository-packages       run commands on top of all packages in given repository
search                    search package details for the given string
shell                     run an interactive DNF shell
swap                      run an interactive dnf mod for remove and install one spec
updateinfo                display advisories about packages
upgrade                   upgrade a package or packages on your system
upgrade-minimal           upgrade, but only 'newest' package match which fixes a problem that affects your system

Optional arguments:
  -c [config file], --config [config file]
                        config file location
  -q, --quiet           quiet operation
  -v, --verbose         verbose operation
  --version             show DNF version and exit
  --installroot [path]  set install root
  --nodocs              do not install documentations
  --noplugins           disable all plugins
  --enableplugin [plugin]
                        enable plugins by name
  --disableplugin [plugin]
                        disable plugins by name
  --releasever RELEASEVER
                        override the value of $releasever in config and repo
                        files
  --setopt SETOPTS      set arbitrary config and repo options
  --skip-broken         resolve depsolve problems by skipping packages
  -h, --help, --help-cmd
                        show command help
  --allowerasing        allow erasing of installed packages to resolve
                        dependencies
  -b, --best            try the best available package versions in
                        transactions.
  -C, --cacheonly       run entirely from system cache, don't update cache
  -R [minutes], --randomwait [minutes]
                        maximum command wait time
  -d [debug level], --debuglevel [debug level]
                        debugging output level
  --debugsolver         dumps detailed solving results into files
  --showduplicates      show duplicates, in repos, in list/search commands
  -e ERRORLEVEL, --errorlevel ERRORLEVEL
                        error output level
  --obsoletes           enables dnf's obsoletes processing logic for upgrade
                        or display capabilities that the package obsoletes for
                        info, list and repoquery
  --rpmverbosity [debug level name]
                        debugging output level for rpm
  -y, --assumeyes       automatically answer yes for all questions
  --assumeno            automatically answer no for all questions
  --enablerepo [repo]
  --disablerepo [repo]
  --repo [repo], --repoid [repo]
                        enable just specific repositories by an id or a glob,
                        can be specified multiple times
  --enable, --set-enabled
                        enable repos with config-manager command
                        (automatically saves)
  --disable, --set-disabled
                        disable repos with config-manager command
                        (automatically saves)
  -x [package], --exclude [package], --excludepkgs [package]
                        exclude packages by name or glob
  --disableexcludes [repo], --disableexcludepkgs [repo]
                        disable excludepkgs
  --repofrompath [repo,path]
                        label and path to additional repository, can be
                        specified multiple times.
  --noautoremove        disable removal of dependencies that are no longer
                        used
  --nogpgcheck          disable gpg signature checking (if RPM policy allows)
  --color COLOR         control whether color is used
  --refresh             set metadata as expired before running the command
  -4                    resolve to IPv4 addresses only
  -6                    resolve to IPv6 addresses only
  --destdir DESTDIR, --downloaddir DESTDIR
                        set directory to copy packages to
  --downloadonly        only download packages
  --comment COMMENT     add a comment to transaction
  --bugfix              Include bugfix relevant packages, in updates
  --enhancement         Include enhancement relevant packages, in updates
  --newpackage          Include newpackage relevant packages, in updates
  --security            Include security relevant packages, in updates
  --advisory ADVISORY, --advisories ADVISORY
                        Include packages needed to fix the given advisory, in
                        updates
  --bzs BUGZILLA        Include packages needed to fix the given BZ, in
                        updates
  --cves CVES           Include packages needed to fix the given CVE, in
                        updates
  --sec-severity {Critical,Important,Moderate,Low}, --secseverity {Critical,Important,Moderate,Low}
                        Include security relevant packages matching the
                        severity, in updates
  --forcearch ARCH      Force the use of an architecture

3. dnf命令的选项解释

dnf命令的选项解释

DNF(Dandified Yum)是Fedora、CentOS、RHEL等Linux发行版上最新的包管理工具,下面是DNF工具常用选项的解释:

1. `install`:安装一个或多个软件包
2. `remove`:卸载一个或多个软件包
3. `update`:更新现有的软件包
4. `upgrade`:更新系统中所有软件包(包括依赖项)
5. `info`:查询软件包详细信息
6. `search`:搜索软件包
7. `list`:列出系统中所有已安装的软件包
8. `clean`:清除系统中的缓存
9. `check-update`:检查系统中可用的更新
10. `repository`:管理 YUM 仓库
11. `module`:管理模块
12. `group`:管理软件包组
13. `config-manager`:管理 DNF 配置文件和库
14. `version`:查看 DNF 版本信息

四、dnf命令的基本使用

1. 查询dnf软件库

  • 查看系统中可用的DNF软件库
[root@jeven ~]# dnf repolist
Extra Packages for Enterprise Linux 7 - x86_64                                                                                         6.5 MB/s |  17 MB     00:02    
CentOS-7 - Base - mirrors.aliyun.com                                                                                                   7.0 MB/s |  10 MB     00:01    
CentOS-7 - Updates - mirrors.aliyun.com                                                                                                8.2 MB/s |  27 MB     00:03    
CentOS-7 - Extras - mirrors.aliyun.com                                                                                                 978 kB/s | 332 kB     00:00    
repo id                                                      repo name                                                                                           status
base                                                         CentOS-7 - Base - mirrors.aliyun.com                                                                10,072
epel                                                         Extra Packages for Enterprise Linux 7 - x86_64                                                      13,753
extras                                                       CentOS-7 - Extras - mirrors.aliyun.com                                                                 515
updates                                                      CentOS-7 - Updates - mirrors.aliyun.com                                                              5,053
  • 查询系统中所有的 DNF软件库,包括可用于不可用的。
[root@jeven ~]# dnf repolist all
Last metadata expiration check: 0:01:45 ago on Mon 03 Jul 2023 07:32:09 PM CST.
repo id                                                repo name                                                                                        status
base                                                   CentOS-7 - Base - mirrors.aliyun.com                                                             enabled: 10,072
centosplus                                             CentOS-7 - Plus - mirrors.aliyun.com                                                             disabled
contrib                                                CentOS-7 - Contrib - mirrors.aliyun.com                                                          disabled
epel                                                   Extra Packages for Enterprise Linux 7 - x86_64                                                   enabled: 13,753
epel-debuginfo                                         Extra Packages for Enterprise Linux 7 - x86_64 - Debug                                           disabled
epel-source                                            Extra Packages for Enterprise Linux 7 - x86_64 - Source                                          disabled
extras                                                 CentOS-7 - Extras - mirrors.aliyun.com                                                           enabled:    515
updates                                                CentOS-7 - Updates - mirrors.aliyun.com                                                          enabled:  5,053

2.查询系统的rpm包

  • 查询系统中所有的软件包,该命令用于列出用户系统上的所有来自软件库的可用软件包和所有已经安装在系统上的软件包。
dnf list

Linux系统之dnf包管理器的基本使用

  • 查询已经安装的rpm包
dnf list installed

Linux系统之dnf包管理器的基本使用

  • 查询可供安装的 RPM 包
dnf list available
  • 搜索软件库中的某个软件包
[root@jeven ~]# dnf search fdisk
Last metadata expiration check: 0:07:32 ago on Mon 03 Jul 2023 07:32:09 PM CST.
======================================================================= Summary Matched: fdisk ========================================================================
gdisk.x86_64 : An fdisk-like partitioning tool for GPT disks
  • 查询某个命令对应的软件名
dnf provides /bin/bash

3. 软件包的安装与卸载

  • 安装软件包
dnf install tree -y

Linux系统之dnf包管理器的基本使用

  • 卸载软件包
dnf remove tree -y
  • 更新软件包
dnf update tree -y

Linux系统之dnf包管理器的基本使用

4. 检查系统软件包的更新

  • 使用以下命令检查系统中所有软件包的更新
dnf check-update

5. 升级所有系统软件包

使用以下命令升级系统中所有有可用升级的软件包

dnf update 或 dnf upgrade

6. 查看dnf命令的执行历史

查看DNF命令的执行历史

[root@jeven ~]# dnf history
ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     1 | install nginx -y         | 2023-07-03 19:47 | Install        |    3   

7. 查看所有的软件包组

查看所有的软件包组

dnf grouplist
  • 安装开发包组
dnf groupinstall "Development Tools" -y

8. 查询软件的详细信息

  • 查看某个软件的详细信息
[root@jeven ~]# dnf info tree
Last metadata expiration check: 0:21:56 ago on Mon 03 Jul 2023 07:32:09 PM CST.
Installed Packages
Name         : tree
Version      : 1.6.0
Release      : 10.el7
Arch         : x86_64
Size         : 87 k
Source       : tree-1.6.0-10.el7.src.rpm
Repo         : @System
Summary      : File system tree viewer
URL          : http://mama.indstate.edu/users/ice/tree/
License      : GPLv2+
Description  : The tree utility recursively displays the contents of directories in a
             : tree-like format.  Tree is basically a UNIX port of the DOS tree
             : utility.

五、dnf命令的使用总结

1. dnf命令的使用总结

  1. 安装软件包:使用dnf install命令,后跟要安装的软件包的名称。例如,dnf install firefox安装Firefox浏览器。
  2. 升级软件包:使用dnf upgrade命令升级所有已安装的软件包。dnf upgrade package-name升级单个软件包。
  3. 搜索软件包:使用dnf search命令搜索要安装的软件包。例如,dnf search mysql搜索MySQL软件包。
  4. 删除软件包:使用dnf remove命令删除已安装的软件包。例如,dnf remove firefox删除Firefox浏览器。
  5. 列出已安装的软件包:使用dnf list installed命令列出所有已安装的软件包。
  6. 列出可用的软件包:使用dnf list available命令列出所有可用的软件包。
  7. 列出软件包的详细信息:使用dnf info package-name命令列出软件包的详细信息。
  8. 清理缓存:使用dnf clean all命令清理DNF缓存。
  9. 禁用或启用软件包仓库:使用dnf config-manager命令禁用或启用软件包仓库。例如,dnf config-manager --disable repository-name禁用软件包仓库。
  10. 检查依赖关系:使用dnf check命令检查软件包之间的依赖关系。

2. dnf与yum包管理器比较

dnf相比于yum有以下几个优点:

  • 性能更好:dnf使用了更先进的依赖关系解决算法,因此速度更快。

  • 交互性更好:dnf提供更友好的命令行交互,支持自动补全、多个软件包同时安装、更好的错误信息提示等功能。

  • 依赖关系处理更加精确:dnf可以非常准确地处理软件包之间的依赖关系,避免因为缺少依赖而导致安装失败的问题。

  • 提供更多的包信息:dnf提供更多、更详细的软件包信息,包括依赖关系、提供的功能、安装的文件以及其他相关信息。

  • 具有扩展性:dnf是基于插件架构设计的,可以方便地扩展新的功能。

点赞
收藏
评论区
推荐文章
Stella981 Stella981
2年前
CentOS 8配置本地yum源及DNF简介
!(https://oscimg.oschina.net/oscnet/eb47834a0576e157aa51568c3b1d7eccac0.gif)CentOS8更改了软件包的安装程序,取消了yum的配置方法,改而使用了dnf作为安装程序。虽然改变了软件包的安装方式,但是dnf还是能兼容使用yum的配置文件和命令的使用方法
Wesley13 Wesley13
2年前
Java爬虫之JSoup使用教程
title:Java爬虫之JSoup使用教程date:201812248:00:000800update:201812248:00:000800author:mecover:https://imgblog.csdnimg.cn/20181224144920712(https://www.oschin
Stella981 Stella981
2年前
CentOS 安装dnf软件包管理器
DNF即DandifiedYUM,基于RPM,Linux发行版下一代软件包管理工具。它首先在Fedora18中出现,并且在最近发行的Fedora22中替代YUM工具集。CentOS和OpenSUSE等Linux发行版也可以使用。yum已经有些老旧,不堪大用。下文将介绍怎么安装DNF软件包管理器,默认已经切换到root用户,如果没有切换,
Wesley13 Wesley13
2年前
DNF包管理器不升级指定包的配置
使用fedora作为日常系统使用有一年了,上半年开始使用搜狗输入法作为系统的输入法,最近使用系统的升级命令sudodnfupdatey进行升级,然后就自动的把搜狗输入法升级到2.1的新版本了,然后就不能使用了,切换回老版本2.0,就一切正常了,然后就开始了探索让dnf不升级搜狗输入法的方法。经过观察,指导搜狗输入法主要需要单独安装
Stella981 Stella981
2年前
Linux运维常见面试题之精华收录
Linux运维常见面试题之精华收录1、什么是运维?什么是游戏运维?1)运维是指大型组织已经建立好的网络软硬件的维护,就是要保证业务的上线与运作的正常,在他运转的过程中,对他进行维护,他集合了网络、系统、数据库、开发、安全、监控于一身的技术运维又包括很多种,有DBA运维、网站运维、虚
Stella981 Stella981
2年前
Fedora 24系统基本命令
Fedora 24基本命令一、    DNF软件管理1.     修改配置:在/etc/dnf/dnf.conf中加入fastestmirrortrue、keepcachetrue2.     更新软件:dnf update、apt upgrade3.   
江湖有缘 江湖有缘
7个月前
Linux系统之VNC服务设置方法
Linux系统之VNC服务设置方法
江湖有缘 江湖有缘
7个月前
Linux系统之查看进程监听端口方法
Linux系统之查看进程监听端口方法
江湖有缘 江湖有缘
7个月前
Linux系统基础之locate命令
Linux系统基础之locate命令
江湖有缘 江湖有缘
6个月前
Linux系统之Bonding 网卡绑定配置方法
Linux系统之Bonding网卡绑定配置方法
江湖有缘
江湖有缘
Lv1
各大IT社区专家博主,华为HCIE云计算认证等,路漫漫其修远兮,吾将上下而求索!
文章
10
粉丝
0
获赞
2