DNF, or Dandified Yum, is a package manager in some Linux distributions. It is the next-generation version of the Yum (Yellowdog Updater, Modified) package manager, widely used in Red Hat-based systems. DNF was introduced as a replacement for Yum to address some limitations and improve performance.

DNF is commonly used in Rocky Linux, Fedora, RHEL (Red Hat Enterprise Linux) 8 and later, and other Linux distributions that have adopted it as their package manager. It aims to provide users and administrators a more modern and efficient package management experience.

https://docs.rockylinux.org/10/guides/package_management/dnf_package_manager/

DNF(全称Dandified Yum)是部分Linux发行版中的软件包管理器。作为Yum(Yellowdog Updater Modified)的下一代版本,它广泛应用于基于Red Hat的系统中。DNF被引入以取代Yum,旨在解除原有局限并提升性能表现。

该器具常见于Rocky Linux、Fedora、RHEL(红帽企业版Linux)8及以上版本等采用其作为包管理器的Linux发行版中,致力于为用户和系统管理员提供更现代化且高效的软件包管理体。

>> dnf install podman
错误:运行此命令需要管理员特权(多数系统下是root用户)。

说明: For all Rocky Linux versions, the ability to use sudo to elevate privileges.

对于所有Rocky Linux版本,能够使用sudo来提升权限。

>> sudo dnf install podman
[sudo] ala 的密码:

命令

sudo dnf install package_name1 package_name2 package_name3

dnf --help
usage: dnf [options] COMMAND

主要命令列表:

alias 列出或创建命令别名
autoremove 删除所有原先因为依赖关系安装的不需要的软件包
check 在包数据库中寻找问题
check-update 检查是否有软件包升级
clean 删除已缓存的内容
deplist [已弃用,请运用 repoquery --deplist] 列出软件包的依赖关系和提供这些软件包的源
distro-sync 同步已经安装的软件包到最新可用版本
downgrade 降级包
group 显示或使用组信息
help 表现一个有援助的用法信息
history 显示或使用事务历史
info 表现关于软件包或软件包组的详细信息
install 向平台中安装一个或多个软件包
list 列出一个或一组软件包
makecache 创建元数据缓存
mark 在已安装的软件包中标记或者取消标记由用户安装的软件包。
module Interact with Modules. WARNING: modularity is deprecated, and functionality will be removed in a future release of DNF5.
provides 查找提供指定内容的软件包
reinstall 重装一个包
remove 从环境中移除一个或多个软件包
repolist 表现已配置的软件仓库
repoquery 搜索匹配关键字的软件包
repository-packages 对指定仓库中的所有软件包运行命令
search 在软件包详细信息中搜索指定字符串
shell 运行一个交互式的 DNF shell
swap 运行一个交互式的 DNF mod 以删除或安装 spec
updateinfo 显示软件包的参考建议
upgrade 升级系统中的一个或多个软件包
upgrade-minimal 升级,但只有“最新”的软件包已修复可能影响你的系统的问题

插件命令列表:

builddep Install build dependencies for package or spec file
changelog 查看软件包的改变日志内容
config-manager 管理 dnf 配置选项和软件仓库
copr 与 Copr 仓库交互。
debuginfo-install 安装调试信息软件包
download 下载软件包至当前目录
groups-manager 创建并编辑组元数据文件
kpatch Toggles automatic installation of kpatch-patch packages
needs-restarting 判断所升级的二进制文件是否得重启
offline-distrosync 准备环境的离线 distrosync
offline-upgrade 准备系统的离线升级
playground 与 Playground 仓库交互。
repoclosure 显示仓库中未被解决的依赖关系的列表
repodiff 列出两组仓库中的不同
repograph 以点线图方式输出完整的软件包依赖关系图
repomanage 管理 RPM 软件包目录
reposync 下载远程仓库中的全部软件包
system-upgrade 准备系统以升级到新版本

General DNF options:
-c [config file], --config [config file]
配置文件位置
-q, --quiet 静默执行
-v, --verbose 详尽执行
--version 显示 DNF 的版本并退出
--installroot [path] 设置目标根目录
--nodocs 不要安装文档
--noplugins 禁用所有插件
--enableplugin [plugin]
启用指定名称的插件
--disableplugin [plugin]
禁用指定名称的插件
--releasever RELEASEVER
覆盖在配置文件和仓库材料中 $releasever 的值
--releasever-major RELEASEVER_MAJOR
override the value of $releasever_major in config and repo files
--releasever-minor RELEASEVER_MINOR
override the value of $releasever_minor in config and repo files
--setopt SETOPTS 设置任意设置和仓库选项
--skip-broken 借助跳过软件包来解决依赖问题
-h, --help, --help-cmd
显现命令帮助
--allowerasing 允许解决依赖关系时删除已安装软件包
-b, --best 在事务中尝试最佳软件包版本。
--nobest 不将事务限制在最佳候选
-C, --cacheonly 完全从系统缓存运行,不升级缓存
-R [minutes], --randomwait [minutes]
最大命令等待时间
-d [debug level], --debuglevel [debug level]
调试输出级别
--debugsolver 转储详细解决结果至档案
--showduplicates 在 list/search 命令下,显示仓库里重复的条目
-e ERRORLEVEL, --errorlevel ERRORLEVEL
错误输出级别
--obsoletes 对 upgrade 启用 dnf 的过期处理逻辑,或对 info、list 和 repoquery 启用软件包过期的显示功能
--rpmverbosity [debug level name]
rpm调试输出等级
-y, --assumeyes 全部问题自动应答为是
--assumeno 全部困难自动应答为否
--enablerepo [repo] 为当前 dnf 命令临时启用仓库。接受一个 id、以逗号分隔的多个 id 列表,或 ids glob。此选项可多次指定。
--disablerepo [repo] 为当前 dnf 命令临时禁用仓库。接受一个 id、以逗号分隔的多个 id 列表,或 ids glob。此选项可多次指定,但它与 `--repo` 是相互排斥的。
--repo [repo], --repoid [repo]
启用指定 id 或 glob 的仓库,可能指定多次
--enable 使用 config-manager 命令启用 repos (自动保存)
--disable 启用 config-manager 命令禁用 repos (自动保存)
-x [package], --exclude [package], --excludepkgs [package]
用全名或通配符排除软件包
--disableexcludes [repo], --disableexcludepkgs [repo]
禁用 excludepkgs
--repofrompath [repo,path]
附加仓库所要使用的标签和路径(与 baseurl 中的路径一致),可以指定多次。
--noautoremove 禁用删除不再被运用的依赖软件包
--nogpgcheck 禁用 gpg 签名检查 (倘若 RPM 策略允许)
--color COLOR 配置是否使用颜色
--refresh 在运行命令之前将元数据标记为过期
-4 仅解析 IPv4 地址
-6 仅解析 IPv6 地址
--destdir DESTDIR, --downloaddir DESTDIR
设置软件包要复制到的目录
--downloadonly 仅下载软件包
--transient Use a transient overlay which will reset on reboot
--comment COMMENT 为事务添加一个注释
--bugfix 在更新中包括与 bug 修复有关的软件包
--enhancement 在更新中包括与功能增强有关的软件包
--newpackage 在更新中包括与新软件包有关的软件包
--security 在更新中包括与安全有关的软件包
--advisory ADVISORY, --advisories ADVISORY
在更新中包括修复指定公告所必须的软件包
--bz BUGZILLA, --bzs BUGZILLA
在更新中包括修复给定 BZ 所必须的软件包
--cve CVES, --cves CVES
在更新中包括修复给定 CVE 所必须的软件包
--sec-severity {Critical,Important,Moderate,Low}, --secseverity {Critical,Important,Moderate,Low}
在更新中包括匹配给定安全等级的安全相关的软件包
--forcearch ARCH 强制采用一个架构

DNF repository configuration

The configuration file for DNF and its associated utilities can be found at /etc/dnf/dnf.conf. Within this file, there is a mandatory [main] section that allows the configuration of DNF options with global effects. Additionally, it may include one or more [repository] sections, providing the ability to set repository-specific options.

Any values specified in the [repository] sections of the /etc/dnf/dnf.conf file will take precedence over values set in the [main] section.

DNF及其相关工具的配置文件位于/etc/dnf/dnf.conf。该文件包含一个必需的[main]主配置段,用于设置具有全局影响的DNF选项;同时可能包含一个或多个[repository]仓库配置段,用于设置针对特定仓库的选项。

/etc/dnf/dnf.conf文件中,[repository]仓库配置段指定的任何值都将优先于[main]主配置段中设置的值。

cat /etc/dnf/dnf.conf

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

配置信息

dnf config-manager --dump

sudo dnf config-manager --dump
============================================================ main ============================================================
[main]
allow_vendor_change = 1
assumeno = 0
assumeyes = 0
autocheck_running_kernel = 1
bandwidth = 0
best = 1
bugtracker_url = https://bugs.rockylinux.org/
cachedir = /var/cache/dnf
cacheonly = 0
check_config_file_age = 1
clean_requirements_on_remove = 1
color = auto
color_list_available_downgrade = magenta
color_list_available_install = bold,cyan
color_list_available_reinstall = bold,underline,green
color_list_available_upgrade = bold,blue
color_list_installed_extra = bold,red
color_list_installed_newer = bold,yellow
color_list_installed_older = yellow
color_list_installed_reinstall = cyan
color_search_match = bold,magenta
color_update_installed = red
color_update_local = green
color_update_remote = bold,green
config_file_path = /etc/dnf/dnf.conf
countme = 0
debug_solver = 0
debuglevel = 2
defaultyes = 0
deltarpm = 1
deltarpm_percentage = 75
disable_excludes =
diskspacecheck = 1
enabled = 1
enablegroups = 1
errorlevel = 3
exclude =
exclude_from_weak =
exclude_from_weak_autodetect = 1
excludepkgs =
exit_on_lock = 0
fastestmirror = 0
gpgcheck = 1
gpgkey_dns_verification = 0
group_package_types = mandatory, default, conditional
history_list_view = commands
history_record = 1
history_record_packages = dnf, rpm
ignorearch = 0
includepkgs =
install_weak_deps = 1
installonly_limit = 3
installonlypkgs = kernel, kernel-PAE, installonlypkg(kernel), installonlypkg(kernel-module), installonlypkg(vm), multiversion(kernel)
installroot = /
ip_resolve = whatever
keepcache = 0
localpkg_gpgcheck = 0
log_compress = 0
log_rotate = 4
log_size = 1048576
logdir = /var/log
logfilelevel = 9
max_downloads_per_mirror = 3
max_parallel_downloads = 3
metadata_expire = 172800
metadata_timer_sync = 10800
minrate = 1000
module_obsoletes = 0
module_stream_switch = 0
multilib_policy = best
obsoletes = 1
password =
persistdir = /var/lib/dnf
pluginconfpath = /etc/dnf/plugins
pluginpath = /usr/lib/python3.9/site-packages/dnf-plugins
plugins = 1
protect_running_kernel = 1
protected_packages = dnf, setup, systemd, systemd-udev, dnf, yum, sudo, setup, systemd, systemd-udev, dnf, yum, sudo
proxy =
proxy_auth_method = any
proxy_sslcacert =
proxy_sslclientcert =
proxy_sslclientkey =
proxy_sslverify = 1
recent = 7
repo_gpgcheck = 0
reposdir = /etc/yum.repos.d, /etc/yum/repos.d, /etc/distro.repos.d
reset_nice = 1
retries = 10
rpmverbosity = info
showdupesfromrepos = 0
skip_broken = 0
skip_if_unavailable = 0
sslcacert =
sslclientcert =
sslclientkey =
sslverify = 1
sslverifystatus = 0
strict = 1
system_cachedir = /var/cache/dnf
throttle = 0
timeout = 30
transformdb = 1
tsflags =
upgrade_group_objects_upgrade = 1
user_agent = libdnf (Rocky Linux 9.3; generic; Linux.x86_64)
username =
varsdir = /etc/yum/vars, /etc/dnf/vars
zchunk = 1

https://docs.rockylinux.org/10/guides/security/dnf_automatic/

Managing the installation of security updates is an important matter for the system administrator. Providing software updates is a well-trodden path that ultimately causes few problems. For these reasons, it is reasonable to automate the download and application of updates daily and automatically on Rocky servers.

The security of your information system will be strengthened. dnf-automatic is an additional tool that will allow you to achieve this.

管理安全更新的安装是系统管理员的一项重要工作。提供软件更新是一条成熟路径,最终几乎不会引发问题。出于这些原因,在Rocky服务器上每天自动下载和应用更新是合理的做法。

这将增强您信息系统的安全性。dnf-automatic正是实现此目标的辅助工具。

》〉 sudo systemctl edit dnf-automatic.timer

[Unit]
Description=dnf-automatic timer
# See comment in dnf-makecache.service
ConditionPathExists=!/run/ostree-booted
Wants=network-online.target

[Timer]
OnCalendar=*-*-* 6:00
RandomizedDelaySec=10m
Persistent=true

[Install]
WantedBy=timers.target

参考

https://www.runoob.com/linux/linux-comm-dnf.html