openEuler 24.03 dnf 包管理工具命令详解

详解 openEuler 24.03(LTS-SP4)dnf 包管理工具的使用,覆盖软件源配置、search、update、install、remove、list、info、clean、history、upgrade 及 rpm 命令。所有命令与回显均为 openEuler 24.03 实测结果

openEuleropenEuler 24.03Linux系统2026/10/07

openEuler 24.03 dnf 包管理工具命令详解

目标:系统讲解 openEuler 24.03(LTS-SP4)的 dnf 包管理工具,涵盖软件源配置、搜索、安装、卸载、查询、缓存、历史记录与升级等全部常用操作,并展示 rpm 命令的实际用法。所有命令与回显均为 openEuler 24.03 实测结果。

一、环境信息

  • 操作系统:openEuler 24.03(LTS-SP4,VERSION_ID=24.03)
  • 包管理器:dnf 4.16.2(dnf-4.16.2-10.oe2403sp4)、rpm 4.18.2(rpm-4.18.2-34.oe2403sp4)
  • 软件源:openEuler 官方源(repo.openeuler.org)+ 阿里云 docker-ce 源
  • 演示环境:内核 6.8.0-138-generic,x86_64

二、dnf 包管理器概览

dnf 是 RPM 系发行版的新一代包管理器(yum 的下一代),openEuler 24.03 内置 dnf 4.16.2。

查看版本:

dnf --version

实测回显:

4.16.2
  Installed: dnf-0:4.16.2-10.oe2403sp4.noarch at Sun Jun 28 19:33:25 2026
  Built    : http://openeuler.org at Sat Jun 13 08:24:00 2026

  Installed: rpm-0:4.18.2-34.oe2403sp4.x86_64 at Sun Jun 28 19:33:13 2026
  Built    : http://openeuler.org at Sat Jun 13 11:37:54 2026

主配置文件为 /etc/dnf/dnf.conf(实测内容):

[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=True
skip_if_unavailable=False

仓库文件存放于 /etc/yum.repos.d/ 目录,openEuler 24.03 默认包含 openEuler.repo。

三、软件源配置(官方源/国内镜像源)

openEuler 官方源为 repo.openeuler.org,/etc/yum.repos.d/openEuler.repo 中定义了 OS、everything、EPOL、debuginfo、source 等仓库,例如:

[OS]
baseurl=https://repo.openeuler.org/openEuler-24.03-LTS-SP4/OS/$basearch/

[everything]
baseurl=https://repo.openeuler.org/openEuler-24.03-LTS-SP4/everything/$basearch/

[EPOL]
baseurl=https://repo.openeuler.org/openEuler-24.03-LTS-SP4/EPOL/main/$basearch/

新增阿里云 docker-ce 源后,用 dnf repolist 验证(实测回显):

dnf repolist
repo id                             repo name
EPOL                                EPOL
OS                                  OS
debuginfo                           debuginfo
docker-ce-stable                    Docker CE Stable - x86_64
everything                          everything
source                              source
update                              update
update-source                       update-source

详细模式查看仓库信息:

dnf repolist -v

实测回显(节选):

Repo-id            : EPOL
Repo-name          : EPOL
Repo-pkgs          : 4410
Repo-baseurl       : https://repo.openeuler.org/openEuler-24.03-LTS-SP4/EPOL/main/x86_64/

Repo-id            : OS
Repo-name          : OS
Repo-pkgs          : 2465
Repo-baseurl       : https://repo.openeuler.org/openEuler-24.03-LTS-SP4/OS/x86_64/

Repo-id            : debuginfo
Repo-name          : debuginfo
Repo-pkgs          : 3779
Repo-baseurl       : https://repo.openeuler.org/openEuler-24.03-LTS-SP4/debuginfo/x86_64/

Repo-id            : docker-ce-stable
Repo-name          : Docker CE Stable - x86_64
Repo-pkgs          : 252
Repo-baseurl       : https://mirrors.aliyun.com/docker-ce/linux/centos/8/x86_64/stable

💡 配置镜像源要点:openEuler 的 $releasever 解析为 24.03LTS_SP4,阿里云 docker-ce 源需 sed -i 's/\$releasever/8/g' /etc/yum.repos.d/docker-ce.repo 固定为 8,否则仓库 URL 指向不存在的路径。

四、search 搜索

按关键字搜索包(名称、摘要、描述):

dnf search nginx

实测回显(节选):

========================= Name Exactly Matched: nginx ==========================
nginx.x86_64 : A HTTP server, reverse proxy and mail proxy server
nginx.src : A HTTP server, reverse proxy and mail proxy server
======================== Name & Summary Matched: nginx =========================
collectd-nginx.x86_64 : Nginx plugin for collectd
nginx-all-modules.noarch : Nginx modules
nginx-debuginfo.x86_64 : Debug information for package nginx
nginx-debugsource.x86_64 : Debug sources for package nginx
nginx-filesystem.noarch : Filesystem for the Nginx server
nginx-help.noarch : Documents for nginx
nginx-mod-devel.x86_64 : nginx module development
nginx-mod-http-image-filter.x86_64 : HTTP image filter module for nginx
nginx-mod-http-perl.x86_64 : HTTP perl module for nginx
nginx-mod-http-xslt-filter.x86_64 : XSLT module for nginx

五、update 刷新仓库

dnf update(等价于 dnf upgrade)升级所有可更新包。执行前可用 dnf check-update 预览:

dnf check-update

实测回显(节选):

acl.x86_64                           2.3.1-7.oe2403sp4                    update
attr.x86_64                          2.5.1-7.oe2403sp4                    update
coreutils.x86_64                     9.4-23.oe2403sp4                     update
curl.x86_64                          8.4.0-37.oe2403sp4                   update
expat.x86_64                         2.8.1-9.oe2403sp4                    update
gawk.x86_64                          5.2.2-3.oe2403sp4                    update
glibc.x86_64                         2.38-128.oe2403sp4                   update
...

执行全量升级:

dnf update -y

实测回显(节选):

Dependencies resolved.
================================================================================
 Package               Arch       Version                      Repository  Size
================================================================================
Upgrading:
 acl                   x86_64     2.3.1-7.oe2403sp4            update      53 k
 coreutils             x86_64     9.4-23.oe2403sp4             update     2.9 M
 curl                  x86_64     8.4.0-37.oe2403sp4           update     165 k
 glibc                 x86_64     2.38-128.oe2403sp4           update     3.1 M
 glibc-common          x86_64     2.38-128.oe2403sp4           update     2.7 M
 openssl-libs          x86_64     1:3.5.6-7.oe2403sp4          update     3.0 M
 python3               x86_64     3.11.6-45.oe2403sp4          update      10 M
 vim-minimal           x86_64     2:9.0.2092-45.oe2403sp4      update     716 k
 ...

Transaction Summary
================================================================================
Upgrade  40 Packages

Total download size: 39 M
...
Upgraded:
  acl-2.3.1-7.oe2403sp4.x86_64
  coreutils-9.4-23.oe2403sp4.x86_64
  curl-8.4.0-37.oe2403sp4.x86_64
  glibc-2.38-128.oe2403sp4.x86_64
  openssl-libs-1:3.5.6-7.oe2403sp4.x86_64
  vim-minimal-2:9.0.2092-45.oe2403sp4.x86_64
  ...

Complete!

六、install 安装

安装单个包

dnf install -y tree

实测回显(尾部):

  Verifying        : tree-2.1.1-2.oe2403sp4.x86_64                          1/1

Installed:
  tree-2.1.1-2.oe2403sp4.x86_64

Complete!

一次安装多个包

dnf install -y tree lrzsz

实测回显(尾部):

Installed:
  lrzsz-0.12.20-47.oe2403sp4.x86_64        tree-2.1.1-2.oe2403sp4.x86_64

Complete!

💡 RPM 系对应 apt 的 --no-install-recommends 为 --nodocs(跳过 man 手册等文档文件);openEuler 亦支持 --downloadonly 只下载不安装。

七、remove / autoremove 卸载

卸载指定包

dnf remove -y tree

实测回显(尾部):

Removed:
  tree-2.1.1-2.oe2403sp4.x86_64

Complete!

清理孤立的依赖包

dnf autoremove

实测回显:

Dependencies resolved.
Nothing to do.
Complete!

八、list / info 查询

查看已安装的包

dnf list installed tree

实测回显:

Installed Packages
tree.x86_64                        2.1.1-2.oe2403sp4                         @OS

查看仓库中可用的包

dnf list --available nginx

实测回显:

Available Packages
nginx.src                    1:1.24.0-14.oe2403sp4                 update-source
nginx.x86_64                 1:1.24.0-14.oe2403sp4                 update

查看包详情

dnf info tree

实测回显:

Installed Packages
Name         : tree
Version      : 2.1.1
Release      : 2.oe2403sp4
Architecture : x86_64
Size         : 141 k
Source       : tree-2.1.1-2.oe2403sp4.src.rpm
Repository   : @System
From repo    : OS
Summary      : Tree file viewer tool
URL          : http://mama.indstate.edu/users/ice/tree/
License      : GPLv2+
Description  : Tree is a recursive directory listing command that produces a depth indented
             : listing of files, which is colorized ala dircolors if the LS_COLORS environment
             : variable is set and output is to tty.

Available Packages
Name         : tree
Version      : 2.1.1
Release      : 2.oe2403sp4
Architecture : src

查询文件属于哪个包(provides)

dnf provides /usr/bin/tree

实测回显:

tree-2.1.1-2.oe2403sp4.x86_64 : Tree file viewer tool
Repo        : @System
Matched from:
Filename    : /usr/bin/tree

tree-2.1.1-2.oe2403sp4.x86_64 : Tree file viewer tool
Repo        : OS
Matched from:
Filename    : /usr/bin/tree

九、clean / 缓存管理

清理 dnf 缓存(元数据与软件包):

dnf clean all

实测回显:

57 files removed

重新生成缓存:

dnf makecache

实测回显:

EPOL                                            7.0 kB/s | 1.8 kB     00:00
debuginfo                                       7.5 kB/s | 1.8 kB     00:00
source                                          6.7 kB/s | 1.8 kB     00:00
update                                          6.6 kB/s | 1.8 kB     00:00
update-source                                   7.2 kB/s | 1.8 kB     00:00
Metadata cache created.

十、历史记录与升级(history / upgrade)

事务历史

dnf history

实测回显:

ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     4 | install -y tree          | 2026-10-07 06:30 | Install        |    1
     3 | update -y                | 2026-10-07 06:30 | Upgrade        |   40
     2 | install -y docker-ce doc | 2026-10-07 06:28 | Install        |   27 E<
     1 | install -y systemd syste | 2026-09-28 15:22 | I, U           |   16 >

查看最近一次事务详情:

dnf history info

实测回显:

Transaction ID : 4
Begin time     : Wed Oct  7 06:30:43 2026
End time       : Wed Oct  7 06:30:44 2026 (1 seconds)
User           : System <unset>
Return-Code    : Success
Releasever     : 24.03LTS_SP4
Command Line   : install -y tree
Comment        :
Packages Altered:
    Install tree-2.1.1-2.oe2403sp4.x86_64 @OS

upgrade(等价于 update)

系统已是最新时执行 dnf upgrade,实测回显:

update                                          5.4 MB/s |  16 MB     00:02
update-source                                   182 kB/s | 712 kB     00:03
Dependencies resolved.
Nothing to do.
Complete!

十一、rpm 命令速查

rpm 是底层包工具,dnf 的事务最终由 rpm 落地。

列出所有已安装包并统计

rpm -qa | wc -l

实测回显:

183

查看单个包详细信息

rpm -qi tree

实测回显:

Name        : tree
Version     : 2.1.1
Release     : 2.oe2403sp4
Architecture: x86_64
Install Date: Wed Oct  7 06:30:43 2026
Group       : Unspecified
Size        : 144519
License     : GPLv2+
Signature   : RSA/SHA256, Sat Jun 13 08:02:51 2026, Key ID 3b477c60b675600b
Source RPM  : tree-2.1.1-2.oe2403sp4.src.rpm
Build Date  : Sat Jun 13 08:02:49 2026
Build Host  : node-mt2bj.compass-ci.net

十二、常见问题与真实行为

  1. dnf 提示仓库元数据过期:执行 dnf makecache 或 dnf clean all 后重试。

  2. dnf update 下载慢:openEuler 官方源位于国外,可替换为国内镜像源(如 https://mirrors.huaweicloud.com/openeuler/openEuler-24.03-LTS-SP4/...),替换后 dnf clean all && dnf makecache。

  3. dnf list --available <包> 无结果:包可能仅在未启用的仓库中(如 debuginfo/source),或名称拼写不同,用 dnf search 复查。

  4. dnf provides /usr/bin/xxx 无结果:该文件可能由未安装的包提供,先 dnf install -y /usr/bin/xxx 由 dnf 自动定位来源包(provides 的完整能力)。

  5. releasever 为 24.03LTS_SP4:openEuler 的 $releasever 解析特殊,配置 RHEL 系第三方源时需注意固定版本号(例如 docker-ce 源执行 sed -i 's/\$releasever/8/g' /etc/yum.repos.d/docker-ce.repo)。

十三、命令与参数速查表

命令作用常用参数
dnf repolist列出仓库-v 显示详细信息
dnf search <关键字>搜索包
dnf check-update检查可更新包
dnf update / dnf upgrade升级包-y 自动确认
dnf install <包>安装包-y、--nodocs、--downloadonly
dnf download <包>仅下载 rpm--destdir、--resolve
dnf remove <包>卸载包-y
dnf autoremove清理孤立依赖
dnf list列出包installed、--available
dnf info <包>查看包详情
dnf provides <文件>反查文件来源
dnf clean all清理缓存
dnf makecache生成元数据缓存
dnf history事务历史info 查看详情、undo 回滚
rpm -qa列出所有已装包| grep 过滤
rpm -qi <包>查看包详细信息
openEuler 24.03 dnf 包管理工具命令详解 - Quzuo