DNF即Dandified YUM是用于基于RPM发行版的下一代包管理器。首先在Fedora 18中引入它,并且它已经在Fedora 22发行版中替代了YUM工具。DNF以改进YUM瓶颈为目标,即:性能、内存使用,依赖关系解析,速度以及大量其它原因。DNF使用RPM,libsolv和hawkey库进行包管理。虽然它没有在你能够yum,dnf和与yum一起使用它的CentOS和RHEL 7中预装。
DNF没有在RHEL/CentOS7的默认仓库中。但Fedora 22发布时附带了官方实现的DNF。要在RHEL/CentOS系统上按照DNF,你需要首先安装和使能epel-release仓库。
- yum install epel-release
- 或
- yum install epel-release -y
如果这对你无关紧要,你可以预yum一起使用"-y"来自动安装每样东西,而不要用户的干预。下一步,使用yum命令从epel-release仓库安装DNF包。
yum install dnf
检查在你系统上安装的DNF版本。
- [root@instance-z6rhwz8d ~]# dnf --version
- 4.0.9
- Installed: dnf-0:4.0.9.2-2.el7_9.noarch at Tue 19 Jul 2022 12:41:29 PM CST
- Built : CentOS BuildSystem
at Wed 07 Apr 2021 03:52:38 PM CST -
- Installed: rpm-0:4.11.3-45.el7.x86_64 at Tue 26 Jan 2021 11:42:43 AM CST
- Built : CentOS BuildSystem <http://bugs.centos.org> at Wed 30 Sep 2020 05:30:03 PM CST
dnf命令的"repolist"选项,将显示你系统下所有使能的仓库。
- [root@instance-z6rhwz8d ~]# dnf repolist
- Extra Packages for Enterprise Linux 7 - x86_64 78 MB/s | 17 MB 00:00
- CentOS-7 - Base 58 MB/s | 10 MB 00:00
- CentOS-7 - Updates 59 MB/s | 20 MB 00:00
- CentOS-7 - Extras 11 MB/s | 331 kB 00:00
- repo id repo name status
- base CentOS-7 - Base 10,072
- epel Extra Packages for Enterprise Linux 7 - x86_64 13,757
- extras CentOS-7 - Extras 512
- updates CentOS-7 - Updates 4,050
选项"repolist all"将打印在你系统下所有使能/禁用的仓库。
-
- [root@instance-z6rhwz8d ~]# dnf repolist all
- Last metadata expiration check: 0:00:46 ago on Tue 19 Jul 2022 09:02:35 PM CST.
- repo id repo name status
- C7.0.1406-base CentOS-7.0.1406 - Base disabled
- ...
- C7.8.2003-updates CentOS-7.8.2003 - Updates disabled
- base CentOS-7 - Base enabled: 10,072
- base-debuginfo CentOS-7 - Debuginfo disabled
- ...
- epel Extra Packages for Enterprise Linux 7 enabled: 13,757
- ...
- updates CentOS-7 - Updates enabled: 4,050
- updates-source CentOS-7 - Updates Sources disabled
命令"dnf list"将来自所有仓库的所有可用包和在你Linux系统上安装的包。
- [root@instance-z6rhwz8d ~]# dnf list
- Last metadata expiration check: 0:04:02 ago on Tue 19 Jul 2022 09:02:35 PM CST.
- Installed Packages
- GeoIP.x86_64 1.5.0-14.el7 @System
- NetworkManager.x86_64 1:1.18.8-1.el7 @System
- NetworkManager-libnm.x86_64 1:1.18.8-1.el7 @System
- NetworkManager-team.x86_64 1:1.18.8-1.el7 @System
- NetworkManager-tui.x86_64 1:1.18.8-1.el7
- ...
- zziplib-utils.x86_64 0.13.62-12.el7 base
当"dnf list"命令显示来自所有仓库的所有可用的/安装的软件包。但,你使用"list installed"选择只列出安装的包。
- [root@instance-z6rhwz8d ~]# dnf list installed
- Installed Packages
- GeoIP.x86_64 1.5.0-14.el7 @System
- NetworkManager.x86_64 1:1.18.8-1.el7 @System
- NetworkManager-libnm.x86_64 1:1.18.8-1.el7 @System
- ...
- zlib.x86_64 1.2.7-18.el7 @System
"list avallable"选项将列出来自所有使能的仓库可用于安装的所有包。
- [root@instance-z6rhwz8d ~]# dnf list available
- Last metadata expiration check: 16:41:17 ago on Tue 19 Jul 2022 09:02:35 PM CST.
- Available Packages
- 0ad.x86_64 0.0.22-1.el7 epel
- 0ad-data.noarch 0.0.22-1.el7 epel
- 0install.x86_64 2.11-1.el7 epel
- 2048-cli.x86_64 0.9.1-1.el7 epel
- 2048-cli-nocurses.x86_64 0.9.1-1.el7 epel
- 2ping.noarch 3.2.1-2.el7 epel
- 389-admin.x86_64 1.1.46-4.el7 epel
- ...
如果你不知道你想要安装的包,在这种情况中,你可以预dnf命令一起使用'search'选项来搜索配置单词或字符串的包。
- [root@instance-z6rhwz8d ~]# dnf search nano
- Last metadata expiration check: 16:42:36 ago on Tue 19 Jul 2022 09:02:35 PM CST.
- ================================================================ Name Exactly Matched: nano =================================================================
- nano.x86_64 : A small text editor
- nano.x86_64 : A small text editor
- =============================================================== Name & Summary Matched: nano ================================================================
- nanomsg-doc.x86_64 : Documentation for nanomsg
- nanomsg-devel.x86_64 : Development files for nanomsg
- ==================================================================== Name Matched: nano =====================================================================
- nanomsg.x86_64 : Socket library that provides several common communication patterns
- =================================================================== Summary Matched: nano ===================================================================
- perl-Time-Clock.noarch : Twenty-four hour clock object with nanosecond precision
8、查看什么提供了一个文件/子包?
dnf选项"provides"查找提供特定文件/子包的包名。例如,如果你想要在你的系统上查找什么提供了"/bin/bash"。
- [root@instance-z6rhwz8d ~]# dnf provides "/bin/bash"
- Last metadata expiration check: 16:45:33 ago on Tue 19 Jul 2022 09:02:35 PM CST.
- bash-4.2.46-35.el7_9.x86_64 : The GNU Bourne Again shell
- Repo : @System
- Matched from:
- Provide : /bin/bash
-
- bash-4.2.46-34.el7.x86_64 : The GNU Bourne Again shell
- Repo : base
- Matched from:
- Provide : /bin/bash
-
- bash-4.2.46-35.el7_9.x86_64 : The GNU Bourne Again shell
- Repo : updates
- Matched from:
- Provide : /bin/bash
假设在系统上安装一个包前,你想知道它的信息,你使用"info"选项获取一个包的详细信息。
- [root@instance-z6rhwz8d ~]# dnf info nano
- Last metadata expiration check: 16:48:45 ago on Tue 19 Jul 2022 09:02:35 PM CST.
- Installed Packages
- Name : nano
- Version : 2.3.1
- Release : 10.el7
- Arch : x86_64
- Size : 1.6 M
- Source : nano-2.3.1-10.el7.src.rpm
- Repo : @System
- Summary : A small text editor
- URL : http://www.nano-editor.org
- License : GPLv3+
- Description : GNU nano is a small and friendly text editor.
要安装一个称为nano的包,只要运行以下命令,它将自动解析并且按照nano包所有i需要的依赖。
- [root@instance-z6rhwz8d ~]# dnf install nano
- Last metadata expiration check: 16:52:33 ago on Tue 19 Jul 2022 09:02:35 PM CST.
- Dependencies resolved.
- =============================================================================================================================================================
- Package Arch Version Repository Size
- =============================================================================================================================================================
- Installing:
- nano x86_64 2.3.1-10.el7 base 440 k
- ...
-
- Installed:
- nano-2.3.1-10.el7.x86_64
-
- Complete!
你可以只更新一特定包并且保持在系统上所有东西不变。
- [root@instance-z6rhwz8d ~]# dnf update systemd
- Last metadata expiration check: 16:54:56 ago on Tue 19 Jul 2022 09:02:35 PM CST.
- Dependencies resolved.
- Nothing to do.
- Complete!
检查被安装进系统的所有系统包的更新。
- [root@instance-z6rhwz8d ~]# dnf check-update
- Last metadata expiration check: 16:57:06 ago on Tue 19 Jul 2022 09:02:35 PM CST.
-
- NetworkManager.x86_64 1:1.18.8-2.el7_9 updates
- NetworkManager-libnm.x86_64 1:1.18.8-2.el7_9 updates
- NetworkManager-team.x86_64 1:1.18.8-2.el7_9 updates
- NetworkManager-tui.x86_64 1:1.18.8-2.el7_9 updates
- at.x86_64 3.1.13-25.el7_9 updates
你可以用以下命令更新整个系统,包括所有安装的包。
- [root@instance-z6rhwz8d ~]# dnf update
- 或
- [root@instance-z6rhwz8d ~]# dnf upgrade
要移除或者擦除任何不想要的包,你可以与dnf命令一起使用"remove"或"erase"选项来移除它。
- [root@instance-z6rhwz8d ~]# dnf remove nano
- Dependencies resolved.
- ==============================================================================================================
- Package Arch Version Repository Size
- ==============================================================================================================
- Removing:
- nano x86_64 2.3.1-10.el7 @base 1.6 M
- ...
- Removed:
- nano-2.3.1-10.el7.x86_64
-
- Complete!
被安装来满足依赖关系的那些包,如果未被其它程序使用,它们是无用的。要移除那些孤儿包,执行以下命令。
- [root@instance-z6rhwz8d ~]# dnf autoremove
- Last metadata expiration check: 17:07:12 ago on Tue 19 Jul 2022 09:02:35 PM CST.
- Dependencies resolved.
- Nothing to do.
- Complete!
我们很多时候遇到了过时的头以及未完成的事务,在执行dnf时,这导致了错误。我们可以清除包含远程包信息的所有缓存的包和头。
- [root@instance-z6rhwz8d ~]# dnf clean all
- 147 files removed
只要执行以下命令,你可以得到任何特定的DNF命令的帮助。
[root@instance-z6rhwz8d ~]# dnf help info
要列出有关所有可用dnf命令和选项的帮助,只要输入。
- [root@instance-z6rhwz8d ~]# 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
你可以调用dnf历史查看已经执行的dnf命令的列表。你用这种方式知道了带时间戳地安装/移除什么。
- [root@instance-z6rhwz8d ~]# dnf history
- ID | Command line | Date and time | Action(s) | Altered
- -------------------------------------------------------------------------------
- 4 | remove nano | 2022-07-20 14:06 | Removed | 1 <
- 3 | update | 2022-07-20 14:00 | I, U | 121 >#
- 2 | install nano | 2022-07-20 13:55 | Install | 1
- 1 | remove nano | 2022-07-20 13:55 | Removed | 1
命令"dnf grouplist"将打印所有可用或安装地包,如果什么也没有提到,它将列出所有已知组。
- [root@instance-z6rhwz8d ~]# dnf grouplist
- Last metadata expiration check: 0:00:28 ago on Wed 20 Jul 2022 02:23:54 PM CST.
- Available Environment Groups:
- Minimal Install
- Compute Node
- Infrastructure Server
- File and Print Server
- Cinnamon Desktop
- MATE Desktop
- Basic Web Server
- Virtualization Host
- Server with GUI
- GNOME Desktop
- KDE Plasma Workspaces
- Development and Creative Workstation
- Available Groups:
- Cinnamon
- Educational Software
- Electronic Lab
- Fedora Packager
- General Purpose Desktop
- Haskell
- LXQt Desktop
- MATE
- Milkymist
- TurboGears application framework
- Xfce
- Compatibility Libraries
- Console Internet Tools
- Development Tools
- Graphical Administration Tools
- Legacy UNIX Compatibility
- Scientific Support
- Security Tools
- Smart Card Support
- System Administration Tools
- System Management
要按照一个捆绑在一起的包组为一个组包。
- [root@instance-z6rhwz8d ~]# dnf groupinstall 'Educational Software'
- Last metadata expiration check: 1:28:02 ago on Wed 20 Jul 2022 02:23:54 PM CST.
- Dependencies resolved.
- ==============================================================================================================
- Package Arch Version Repository Size
- ==============================================================================================================
- Installing Groups:
- Educational Software
-
- Transaction Summary
- ==============================================================================================================
-
- Is this ok [y/N]: y
- Complete!
通过执行以下命令更新一个组包。
- [root@instance-z6rhwz8d ~]# dnf groupupdate 'Educational Software'
- Last metadata expiration check: 1:29:58 ago on Wed 20 Jul 2022 02:23:54 PM CST.
- Dependencies resolved.
- ==============================================================================================================
- Package Arch Version Repository Size
- ==============================================================================================================
- Installing Groups:
- Educational Software
-
- Transaction Summary
- ==============================================================================================================
-
- Is this ok [y/N]: y
- Complete!
我们可以移除这个组包。
- [root@instance-z6rhwz8d ~]# dnf groupremove 'Educational Software'
- Dependencies resolved.
- ==============================================================================================================
- Package Arch Version Repository Size
- ==============================================================================================================
- Removing Groups:
- Educational Software
-
- Transaction Summary
- ==============================================================================================================
-
- Is this ok [y/N]: y
- Complete!
DNF使得从一个repo(epel)安装任何特定包成为可能。
[root@instance-z6rhwz8d ~]# dnf --enablerepo=epel install phpmyadmin
命令"dnf distro-sync"将提供必要选项来同步所有安装的包到来自任何使能的仓库可用的最新稳定版本。如果没有选择包,同步所有安装的包。
- [root@instance-z6rhwz8d ~]# dnf distro-sync
- Last metadata expiration check: 1:49:18 ago on Wed 20 Jul 2022 02:23:54 PM CST.
- Dependencies resolved.
- Nothing to do.
- Complete!
命令"dnf reinstall nano"将重新安装一个安装过的包。
[root@instance-z6rhwz8d ~]# dnf reinstall nano
如果可能,选项"downgrade"将降级指定名称的包到更低版本。
- [root@instance-z6rhwz8d ~]# dnf downgrade acpid
- Last metadata expiration check: 1:54:15 ago on Wed 20 Jul 2022 02:23:54 PM CST.
- Package acpid of lowest version already installed, cannot downgrade it.
- Error: No packages marked for downgrade.