DNF 是新一代的PMR软件包管理器,是 Yum包管理器的升级版。 DNF 使用 RPM, libsolv 和 hawkey 库进行包管理操作。
Yum是使用RPM软件包管理器的Linux操作系统的免费开放源代码命令行软件包管理应用程序。
Yum是rpm的前端工具,可自动解决软件包的依赖性。它从发行官方存储库和其他第三方存储库安装RPM软件包。
DNF 常用命令
dnf list # DNF列表
dnf list installed # 列出所有安装的RPM包
dnf help # DNF命令帮助
dnf history # 查看DNF命令执行历史
dnf repolist # 查看系统中可使用的DNF软件库
dnf info <package> # 查看软件包详细信息
dnf clean all
dnf makecache
dnf install <package> # 安装软件包及其所需的所有依赖
dnf download $package # 只下载软件包,不安装
dnf update <package> # 升级软件包
dnf remove <package> # 删除软件包
dnf reinstall <package> # 重新安装特定软件包
dnf distro-sync # 更新软件包到最新的稳定发行版
显示版本号
[root@ecs-209716 ~]# dnf --version
4.7.0
Installed: dnf-0:4.7.0-4.el8.noarch at Mon 14 Feb 2022 01:02:53 AM GMT
Built : CentOS Buildsys <bugs@centos.org> at Fri 17 Sep 2021 07:06:14 PM GMT
Installed: rpm-0:4.14.3-19.el8.x86_64 at Mon 14 Feb 2022 01:02:19 AM GMT
Built : CentOS Buildsys <bugs@centos.org> at Fri 15 Oct 2021 05:46:55 PM GMT
查看系统中可使用的DNF软件库
[root@ecs-209716 ~]# dnf repolist
repo id repo name
AppStream CentOS-8.5.2111 - AppStream - mirrors.aliyun.com
base CentOS-8.5.2111 - Base - mirrors.aliyun.com
epel-archive Extra Packages for Enterprise Linux 8 - x86_64
extras CentOS-8.5.2111 - Extras - mirrors.aliyun.com
mysql-connectors-community MySQL Connectors Community
mysql-tools-community MySQL Tools Community
mysql80-community MySQL 8.0 Community Server
显示 epel 仓库的信息
[xxx@ecs-209716 yum.repos.d]$ dnf repolist epel
Repository extras is listed more than once in the configuration
repo id repo name status
epel Extra Packages for Enterprise Linux 8 - x86_64 enabled
更新仓库后,清除缓存
[root@ecs-209716 ~]# dnf clean all
84 files removed
[root@ecs-209716 ~]# dnf makecache
CentOS-8.5.2111 - Base - mirrors.aliyun.com 2.7 MB/s | 4.6 MB 00:01
CentOS-8.5.2111 - Extras - mirrors.aliyun.com 87 kB/s | 10 kB 00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com 2.1 MB/s | 8.4 MB 00:03
CentOS Linux 8 - AppStream 6.7 MB/s | 8.4 MB 00:01
Extra Packages for Enterprise Linux 8 - x86_64 709 kB/s | 13 MB 00:19
Extra Packages for Enterprise Linux 8 - x86_64 2.7 MB/s | 6.4 MB 00:02
MySQL 8.0 Community Server 274 kB/s | 2.5 MB 00:09
MySQL Connectors Community 26 kB/s | 84 kB 00:03
MySQL Tools Community 117 kB/s | 583 kB 00:04
Metadata cache created.
软件卸载
[root@ecs-209716 ~]# dnf remove wget
软件安装
[root@ecs-209716 ~]# dnf install wget
Last metadata expiration check: 0:17:25 ago on Fri 16 Dec 2022 12:24:14 PM CST.
Dependencies resolved.
====================================================================
Package Architecture Version Repository Size
====================================================================
Installing:
wget x86_64 1.19.5-10.el8 AppStream 734 k
Installing dependencies:
libmetalink x86_64 0.1.3-7.el8 base 32 k
Transaction Summary
====================================================================
Install 2 Packages
Total download size: 766 k
Installed size: 2.8 M
Is this ok [y/N]: y
Downloading Packages:
module
一个软件可以有多个版本,每个版本对应一个stream. 在每个stream内部,又分为proile对应到安装场景(比如开发, server, client)。
使用中的要点
如果module有多个stream(版本),会有一个是默认的, 在dnf命令输出里面在stream name后用[d]表示
如果某个stream有多个profiles, 会有一个默认的,在dnf命令输出里面在profile name后用[d]表示
显示 安装模块
dnf module list php
Last metadata expiration check: 3:01:01 ago on Fri 16 Dec 2022 09:23:04 AM CST.
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com
Name Stream Profiles Summary
php 7.2 [d] common [d], devel, minimal PHP scripting language
php 7.3 common [d], devel, minimal PHP scripting language
php 7.4 common [d], devel, minimal PHP scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
解读:php module 有 3个stream(对应3个版本),默认安装的是 7.2 ,7.2 这个stream只有一个profile “common”, 它也是默认安装的profile
$ sudo dnf module list nginx
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)
Name Stream Profiles Summary
nginx 1.14 [d] common [d] nginx webserver
nginx 1.16 common [d] nginx webserver
nginx 1.18 common [d] nginx webserver
nginx 1.20 common [d] nginx webserver
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
————————————————
nginx module 有4个 stream(对应4个版本),默认安装的是1.14,1.14这个stream只有一个profile “common”, 它也是默认安装的profile
常用的库
EPEL 是 Extra Package For Enterprise Linux 的简写,是由 Fedora 项目组为 RHEL & CentOS 提供的第三方扩展包服务。
下载 最新
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
REMI 是一个专为 RedHat 操作系统提供 PHP 各个版本支持的第三方数据源。
下载 最新
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
错误处理
1、 dnf update 时仓库 出错
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
原因 :2020 年 12 月 8 号,CentOS 官方宣布了停止维护 CentOS Linux 的计划,并推出了 CentOS Stream 项目,CentOS Linux 8 作为 RHEL 8 的复刻版本,生命周期缩短,于 2021 年 12 月 31 日停止更新并停止维护(EOL),更多的信息可以查看 CentOS 官方公告。如果需要更新 CentOS,需要将镜像从 mirror.centos.org 更改为 vault.centos.org
修改
cd /etc/yum.repos.d/
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
dnf update