DNF意思是“ Dandified Yum”。 这是下一代的yum软件包管理器(Yum的派生)。DNF命令使用libsolv,hawkey,ibrepo和libcomps等C语言库编写。它是在Fedora 18中引入的,自Fedora 22以来它一直是默认的软件包管理器。
DNF是一个软件包管理器,可以在基于RPM的Linux发行版上安装,更新和删除软件包。 它会自动计算依赖性并确定安装软件包所需的操作。由于一些长期问题尚未在yum中解决,如性能差,内存使用率高,依赖关系解析速度慢等,yum已被DNF取代。这不仅仅是解决yum中待解决的问题。 此外,DNF添加了许多功能,以实现基于RPM的系统中软件包的无缝管理。
默认情况下,DNF已安装在RHEL 8和CentOS 8系统上。 运行以下命令以在CentOS 7和RHEL 8系统上安装。
DNF软件包可以通过yum命令安装在CentOS 7系统上,因为它是Extras Repo的一部分。 为RHEL 7系统启用“ rhel-7-server-extras-rpms”存储库。
# yum install dnf
DNF命令的语法类似于YUM,你会发现它们之间有很多相似之处。
dnf [Option] [Command] [Package_Name]
Main Configuration: /etc/dnf/dnf.conf
Repository: /etc/yum.repos.d/
Cache Files: /var/cache/dnf
+---------------------+-------------------------------------------------------------------------------------------+
| Command | Description |
+---------------------+-------------------------------------------------------------------------------------------+
|repolist | Display the configured software repositories |
|install | Install a single or multiple packages on your system |
|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 |
|list | List a package or groups of packages |
|info | Display details about a package or group of packages |
|updateinfo | Display advisories about packages |
|search | Search package details for the given string |
|check-update | Check for available package upgrades |
|remove | Remove a package or packages from your system |
|reinstall | Reinstall a package |
|downgrade | Downgrade a package |
|autoremove | Remove all unneeded packages that were originally installed as dependencies |
|distro-sync | Synchronize installed packages to the latest available versions |
|makecache | Generate the metadata cache |
|repository-packages | Run commands on top of all packages in given repository |
|provides | Find what package provides the given value |
|group | Display, or use, the groups information |
|history | Display, or use, the transaction history |
|clean | Remove cached data |
|help | Display a helpful usage message |
+---------------------+-------------------------------------------------------------------------------------------+
该命令列出了默认情况下启用的所有仓库,并提供了列出其他信息的选项。 在通过dnf命令添加-v
选项时,可提供了更详细的信息。
此外,它不会强制同步过期的元数据,并且你可以强制同步使用--refresh
开关启用的所有存储库。
# dnf repolist
Last metadata expiration check: 0:01:18 ago on Tue 10 Dec 2019 02:05:20 PM IST.
repo id repo name status
AppStream CentOS-8 - AppStream 5,089
BaseOS CentOS-8 - Base 2,843
*epel Extra Packages for Enterprise Linux 8 - x86_64 3,625
extras CentOS-8 - Extras 3
# dnf repolist enabled
or
# dnf repolist --enabled
# dnf repolist disabled
or
# dnf repolist --disabled
# dnf repolist all
or
# dnf repolist --all
-v
开关。 它显示repo-id,repo-name等。# dnf repolist -v
.
.
Repo-id : BaseOS
Repo-name : CentOS-8 - Base
Repo-revision: 8.0.1905
Repo-distro-tags: [cpe:/o:centos:centos:8]: , 8, C, O, S, e, n, t
Repo-updated : Fri 01 Nov 2019 01:44:36 AM IST
Repo-pkgs : 2,843
Repo-size : 3.8 G
Repo-mirrors : http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=BaseOS&infra=stock
Repo-baseurl : http://mirrors.piconets.webwerks.in/centos-mirror/8.0.1905/BaseOS/x86_64/os/ (9 more)
Repo-expire : 172,800 second(s) (last: Tue 10 Dec 2019 02:05:01 PM IST)
Repo-filename: /etc/yum.repos.d/CentOS-Base.repo
.
.
下面我们安装nano,MariaDB服务器和MariaDB客户端软件包。 默认情况下,每次DNF要求您确认安装软件包时,都添加-y
选项以避免确认。
# dnf install nano
# dnf install MariaDB-server MariaDB-client
-y
选项以安装软件包,无需确认直接安装:# dnf install nano -y
# dnf --disablerepo="*" --enablerepo=epel install htop
# dnf install /path/to/file.rpm
# dnf install https://xyz.com/file.rpm
要安装提供/usr/bin/[xxx]文件的软件包,请运行以下命令。
例如,sar应用程序是“ systat”软件包的一部分,但我们大多数人都不知道其父软件包的名称。 但是,很难找到其父程序包名称,但是此命令允许您在不知道父程序包名称的情况下进行安装。
# dnf install /usr/bin/sar
# dnf install --advisory=FEDORA-2018-b7b99fe852 \*
–advisory ADVISORY : Include packages needed to fix the given advisory, in updates
# dnf remove nano -y
# dnf remove --duplicates
# dnf autoremove
# dnf upgrade
# dnf upgrade [Package_Name]
# dnf upgrade nano
# dnf upgrade [Package_Version]
# dnf upgrade nano-2.9.8-1
以下命令将显示有关更新建议的信息。这显示了可用于安全性,错误修复和增强的软件包更新数量。
这些软件包可以通过“ dnf upgrade”命令进行升级。
# dnf updateinfo list
Last metadata expiration check: 0:21:23 ago on Wed 11 Dec 2019 10:36:15 AM IST.
FEDORA-EPEL-2019-1897c58d3f bugfix epel-release-8-7.el8.noarch
# dnf updateinfo info FEDORA-EPEL-2019-1897c58d3f
Last metadata expiration check: 0:20:57 ago on Wed 11 Dec 2019 10:36:15 AM IST.
===============================================================================
epel-release-8-7.el8
===============================================================================
Update ID: FEDORA-EPEL-2019-1897c58d3f
Type: bugfix
Updated: 2019-12-10 07:26:18
Bugs: 1760182 - Unknown confg values are set
Description: Remove failovermethod from EPEL8 tree. It is no longer needed.
Severity: None
如果只想在系统上更新错误修正,增强或安全修正包,请使用以下命令。
# dnf upgrade-minimal
# dnf upgrade-minimal [Package_Name]
此命令检查系统上是否有任何软件包更新。
# dnf check-update
# dnf list updates
# dnf check-update [Package_Name]
# dnf check-update nano
此命令检查本地包装,并生成有关已检测到的任何问题的信息。你可以通过选项限制“packagedb”检查–dependencies,–duplicates,–obsoleted或–provides。
# dnf check
dnf list命令将打印我们知道的所有软件包,无论是在RPMDB中,在存储库中还是在两者中。您可以根据需要控制输出。
# dnf list
or
# dnf list all
# dnf list installed
# dnf list available
# dnf list installed httpd
Installed Packages
httpd.x86_64 2.4.37-12.module_el8.0.0 + 185 + 5908b0db @AppStream
# dnf list obsoletes
# dnf list recent
# dnf list upgrades
# dnf list autoremove
dnf search命令使您可以根据给定的字符串查找可用软件包的列表。当你不知道要安装的确切软件包名称时,这将非常有用。
它在包数据中搜索给定的关键字。关键字作为不区分大小写的子字符串进行匹配,支持全局。默认情况下,列出与所有请求的密钥匹配的软件包。在软件包名称和摘要中搜索关键字。
# dnf search ftpd
Last metadata expiration check: 0:09:00 ago on Thu 12 Dec 2019 11:23:07 AM IST.
=================================== Name & Summary Matched: ftpd ====================================
pure-ftpd-selinux.x86_64 : SELinux support for Pure-FTPD
======================================== Name Matched: ftpd =========================================
vsftpd.x86_64 : Very Secure Ftp Daemon
pure-ftpd.x86_64 : Lightweight, fast and secure FTP server
nordugrid-arc-gridftpd.x86_64 : ARC gridftp server
上面的输出显示了ftpd关键字的匹配字符串。
以下命令用于列出有关已安装和可用软件包的描述和摘要信息。
此命令使您可以检查有关回购中可用软件包的详细信息。它显示了有关软件包的各种信息,例如名称,Arch,版本,发行版,大小,存储库名称等。
# dnf info httpd
Last metadata expiration check: 23:44:19 ago on Wed 11 Dec 2019 11:35:25 AM IST.
Installed Packages
Name : httpd
Version : 2.4.37
Release : 12.module_el8.0.0+185+5908b0db
Arch : x86_64
Size : 4.9 M
Source : httpd-2.4.37-12.module_el8.0.0+185+5908b0db.src.rpm
Repo : @System
From repo : AppStream
Summary : Apache HTTP Server
URL : https://httpd.apache.org/
License : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
: web server.
dnf prvides命令将查找提供给定文件的软件包。如果您想找出哪个软件包(已安装或未安装)提供了此文件,这将很有用。
# dnf provides sar
Last metadata expiration check: 0:27:57 ago on Thu 12 Dec 2019 11:23:07 AM IST.
sysstat-11.7.3-2.el8.x86_64 : Collection of performance monitoring tools for Linux
Repo : AppStream
Matched from:
Filename : /usr/bin/sar
# dnf makecache
CentOS-8 - AppStream 1.6 kB/s | 4.3 kB 00:02
CentOS-8 - Base 1.4 kB/s | 3.9 kB 00:02
CentOS-8 - Extras 503 B/s | 1.5 kB 00:03
Extra Packages for Enterprise Linux 8 - x86_64 5.6 kB/s | 10 kB 00:01
Extra Packages for Enterprise Linux 8 - x86_64 710 kB/s | 4.2 MB 00:06
Metadata cache created.
# dnf check-update
# dnf check-update [Package_Name]
# dnf check-update nano
# dnf check-update ghostscript.x86_64 --changelog
Last metadata expiration check: 0:01:44 ago on Fri 13 Dec 2019 11:25:15 AM IST.
ghostscript.x86_64 9.25-2.el8_0.3 AppStream
Changelogs for ghostscript-9.25-2.el8_0.3.x86_64
* Thu Aug 22 12:00:00 AM 2019 Martin Osvald - 9.25-2.3
- Resolves: #1744010 - CVE-2019-14811 ghostscript: Safer Mode Bypass by .forceput Exposure in .pdf_hook_DSC_Creator (701445)
- Resolves: #1744014 - CVE-2019-14812 ghostscript: Safer Mode Bypass by .forceput Exposure in setuserparams (701444)
- Resolves: #1744005 - CVE-2019-14813 ghostscript: Safer Mode Bypass by .forceput Exposure in setsystemparams (701443)
- Resolves: #1744230 - CVE-2019-14817 ghostscript: Safer Mode Bypass by .forceput Exposure in .pdfexectoken and other procedures (701450)
* Mon Aug 05 12:00:00 AM 2019 Martin Osvald - 9.25-2.2
- Resolves: #1737336 - CVE-2019-10216 ghostscript: -dSAFER escape via .buildfont1 (701394)
* Thu Mar 28 12:00:00 AM 2019 Martin Osvald - 9.25-2.1
- Resolves: #1692798 - CVE-2019-3839 ghostscript: missing attack vector
protections for CVE-2019-6116
- Resolves: #1678170 - CVE-2019-3835 ghostscript: superexec operator
is available (700585)
- Resolves: #1691414 - CVE-2019-3838 ghostscript: forceput in DefineResource
is still accessible (700576)
- fix included for ghostscript: Regression: double comment chars
'%' in gs_init.ps leading to missing metadata
- fix for pdf2dsc regression added to allow fix for CVE-2019-3839
dnf downgrade命令用于将指定的软件包降级到较低(先前)的版本。如果提供已安装软件包的任何特定版本,则它将降级为目标版本。
# dnf downgrade nano
如果他们的软件包已经安装,则此命令用于重新安装。如果尚未安装,则会收到以下消息。
Package nano available, but not installed.
No match for argument: nano
Error: No packages marked for reinstall.
# dnf reinstall nano
# dnf group list
or
# dnf grouplist
Last metadata expiration check: 1:38:20 ago on Fri 13 Dec 2019 11:25:15 AM IST.
Available Environment Groups:
Server with GUI
Server
Minimal Install
KDE Plasma Workspaces
Virtualization Host
Custom Operating System
Installed Environment Groups:
Workstation
Available Groups:
Container Management
.NET Core Development
RPM Development Tools
Smart Card Support
Development Tools
Graphical Administration Tools
Headless Management
Legacy UNIX Compatibility
Network Servers
Scientific Support
Security Tools
System Tools
Fedora Packager
# dnf group summary
Last metadata expiration check: 1:48:35 ago on Fri 13 Dec 2019 11:25:15 AM IST.
Available Groups: 13
此命令显示该组中可用软件包的列表。
每个小组分为三个部分,详细信息如下:
# dnf group info 'Development Tools'
Last metadata expiration check: 1:54:38 ago on Fri 13 Dec 2019 11:25:15 AM IST.
Group: Development Tools
Description: A basic development environment.
Mandatory Packages:
autoconf
automake
binutils
bison
flex
gcc
gcc-c++
gdb
glibc-devel
libtool
make
pkgconf
pkgconf-m4
pkgconf-pkg-config
redhat-rpm-config
rpm-build
rpm-sign
strace
Default Packages:
asciidoc
byacc
ctags
diffstat
git
intltool
ltrace
patchutils
perl-Fedora-VSP
perl-generators
pesign
source-highlight
systemtap
valgrind
valgrind-devel
Optional Packages:
cmake
expect
rpmdevtools
rpmlint
运行以下命令以安装软件包组。
在这种情况下,我们将安装“开发工具”软件包组。编辑器组捆绑了许多与编辑器相关的软件包。
# dnf group install 'Development Tools' -y
or
# dnf groupinstall 'Development Tools' -y
# dnf group update 'Development Tools' -y
or
# dnf groupupdate 'Development Tools' -y
# dnf group remove 'Development Tools'
or
# dnf group erase 'Development Tools'
默认情况下,当您执行各种dnf操作时,dnf会将包和存储库元数据之类的数据缓存到“/var/cache/dnf”目录中。该缓存在一段时间内会占用大量空间。这将允许您删除所有缓存的数据。
# dnf clean dbcache
# dnf clean metadata
# dnf clean packages
dnf clean all
# dnf history
ID | Command line | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
9 | install nano | 2019-12-12 12:49 | Install | 1
8 | erase nano -y | 2019-12-11 08:09 | Removed | 1
7 | install nano -y | 2019-12-11 08:09 | Install | 1
6 | remove nano | 2019-12-11 08:09 | Removed | 1
5 | install httpd -y | 2019-12-11 08:08 | Install | 9
4 | | 2019-11-10 21:27 | Install | 4
3 | install fping | 2019-11-09 10:09 | Install | 1
2 | install epel-release | 2019-11-09 10:04 | Install | 1
1 | | 2019-11-09 09:10 | Install | 1441 EE
# dnf history list
# dnf history info
Transaction ID : 9
Begin time : Thu 12 Dec 2019 12:49:17 PM IST
Begin rpmdb : 1442:1d39bf569934f62170179ac566e748a34156008a
End time : Thu 12 Dec 2019 12:49:18 PM IST (1 seconds)
End rpmdb : 1443:e5cdaaca00923c394bd2533c642c175ec6ce2cf7
User : root
Return-Code : Success
Releasever : 8
Command Line : install nano
Packages Altered:
Install nano-2.9.8-1.el8.x86_64 @BaseOS
# dnf history info 3
Transaction ID : 3
Begin time : Sat 09 Nov 2019 10:09:19 AM IST
Begin rpmdb : 1429:4ea1748d2132285a5bc1929f522f97f80bc5cede
End time : Sat 09 Nov 2019 10:09:20 AM IST (1 seconds)
End rpmdb : 1430:7c974a655a4f3a6c0ad5c6b8ab968279e0144581
User : root
Return-Code : Success
Releasever : 8
Command Line : install fping
Packages Altered:
Install fping-4.2-2.el8.x86_64 @epel
# dnf history redo 3
# dnf history undo 3
# dnf history rollback 7
# dnf install dnf-automatic
# systemctl enable dnf-automatic.timer
Created symlink from /etc/systemd/system/basic.target.wants/dnf-automatic.timer to /usr/lib/systemd/system/dnf-automatic.timer
# systemctl start dnf-automatic.timer
dnf mark命令允许你始终将指定的程序包保留在系统上,并且在运行自动删除命令时不从系统中删除此程序包。
# dnf mark install nano
nano-2.9.8-1.el8.x86_64 marked as user installed.
# dnf mark remove nano
nano-2.9.8-1.el8.x86_64 unmarked as user installed.
# dnf repoquery htop
Last metadata expiration check: 0:22:18 ago on Sat 14 Dec 2019 02:44:16 PM IST.
htop-0:2.2.0-6.el8.x86_64
我们在本文中添加了所有可能的选项,但是如果您正在寻找其他任何未在本文中列出的选项,请访问手册页。
# dnf -help
or
# man dnf