centos8平台使用dnf/yum管理软件包 您所在的位置:网站首页 centos8安装jdk17 centos8平台使用dnf/yum管理软件包

centos8平台使用dnf/yum管理软件包

2023-04-10 00:52| 来源: 网络整理| 查看: 265

一,dnf的用途

centos7开始,DNF 成为了默认的软件包管理器,同时 yum 仍然是可用的

DNF包管理器克服了YUM包管理器的一些瓶颈,提升了用户体验,内存占用,依赖分析,运行速度等方面

DNF使维护软件包组变得容易,并且能够自动解决依赖性问题

 

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

         对应的源码可以访问这里获取: https://github.com/liuhongdi/

 说明:作者:刘宏缔 邮箱: [email protected]

 

二,dnf所属的包

1,dnf所属的包

[root@blog zshfile]# whereis dnf dnf: /usr/bin/dnf /etc/dnf /usr/share/man/man8/dnf.8.gz [root@blog zshfile]# rpm -qf /usr/bin/dnf dnf-4.2.7-7.el8_1.noarch

 

2,yum所属的包:

[root@blog zshfile]# whereis yum yum: /usr/bin/yum /etc/yum /etc/yum.conf /usr/share/man/man8/yum.8.gz [root@blog zshfile]# ll /usr/bin/yum lrwxrwxrwx 1 root root 5 Dec 19 23:43 /usr/bin/yum -> dnf-3

可见yum是一个符号链接,链接到了dnf-3

[root@blog zshfile]# whereis dnf-3 dnf-3: /usr/bin/dnf-3 [root@blog zshfile]# rpm -qf /usr/bin/dnf-3 python3-dnf-4.2.7-7.el8_1.noarch

 

三,查看dnf的版本和帮助

1,查看版本

[root@blog zshfile]# dnf --version 4.2.7 Installed: dnf-0:4.2.7-7.el8_1.noarch at Thu 05 Mar 2020 02:18:51 AM GMT Built : CentOS Buildsys at Thu 19 Dec 2019 03:44:23 PM GMT Installed: rpm-0:4.14.2-11.el8_0.x86_64 at Wed 25 Dec 2019 03:36:22 AM GMT Built : CentOS Buildsys at Tue 01 Oct 2019 01:45:29 PM GMT

 

2,查看帮助

[root@blog zshfile]# dnf --help

 

3,查看手册

[root@blog zshfile]# man dnf

 

四,dnf操作例子:对repo的查询

1,列出系统上的存储库,状态是enabled

[root@blog ~]# dnf repolist

说明:这个命令等价于 dnf repolist enabled

 

2,列出所有的存储库:(包括enabled/disabled)

[root@blog ~]# dnf repolist all

 

3,列出未安装到系统的repo(状态是disabled)

[root@blog ~]# dnf repolist disabled

 

4,查看某个repo的详细信息

[root@blog ~]# dnf repolist -v BaseOS

说明:也可以用repoinfo

[root@blog ~]# dnf repoinfo BaseOS

 

五,dnf操作例子:对软件包的查询、搜索

1,列出所有软件包:

(包括可安装的和已安装的)

[root@blog ~]# dnf list

说明:显示分成两部分:

Installed Packages     已安装的包

Available Packages     可安装的包

注意 repo前加了@符的,表示是已安装的

 

2,列出已安装的软件包

[root@blog ~]# dnf list installed

 

3,列出所有可安装的软件包:

[root@blog ~]# dnf list available

 

4,查看包的详细信息

# info:查看rpm包的详细信息

[root@blog ~]# dnf info zsh Last metadata expiration check: 0:14:50 ago on Sun 12 Apr 2020 07:27:24 PM CST. Installed Packages Name : zsh Version : 5.5.1 Release : 6.el8 Architecture : x86_64 Size : 6.9 M Source : zsh-5.5.1-6.el8.src.rpm Repository : @System Summary : Powerful interactive shell URL : http://zsh.sourceforge.net/ License : MIT Description : The zsh shell is a command interpreter usable as an interactive login : shell and as a shell script command processor. Zsh resembles the ksh : shell (the Korn shell), but includes many enhancements. Zsh supports : command line editing, built-in spelling correction, programmable : command completion, shell functions (with autoloading), a history : mechanism, and more. Available Packages Name : zsh Version : 5.5.1 Release : 6.el8_1.2 Architecture : x86_64 Size : 2.9 M Source : zsh-5.5.1-6.el8_1.2.src.rpm Repository : BaseOS Summary : Powerful interactive shell URL : http://zsh.sourceforge.net/ License : MIT Description : The zsh shell is a command interpreter usable as an interactive login : shell and as a shell script command processor. Zsh resembles the ksh : shell (the Korn shell), but includes many enhancements. Zsh supports : command line editing, built-in spelling correction, programmable : command completion, shell functions (with autoloading), a history : mechanism, and more.

分别列出了已安装和可获得的两个rpm包的信息

 

5,搜索rpm包

[root@blog ~]# dnf search zsh Last metadata expiration check: 0:14:10 ago on Sun 12 Apr 2020 07:27:24 PM CST. ====================================== Name Exactly Matched: zsh ========================================= zsh.x86_64 : Powerful interactive shell ========================================= Name & Summary Matched: zsh ===================================== zsh-html.noarch : Zsh shell manual in html format zsh-syntax-highlighting.noarch : Fish shell like syntax highlighting for Zsh =================================================== Name Matched: zsh ====================================== cekit-zsh-completion.noarch : Container image creation tool

 

6,查询指定的文件属于哪个软件包?

#provides:查看是哪个软件包提供了系统中的某一文件

[root@blog ~]# dnf provides /usr/bin/zsh Last metadata expiration check: 0:48:19 ago on Sun 12 Apr 2020 07:27:24 PM CST. zsh-5.5.1-6.el8.x86_64 : Powerful interactive shell Repo : @System Matched from: Filename : /usr/bin/zsh

 

7,列出指定仓库拥有的软件包

[root@centos8 yum.repos.d]# dnf list --repo epel

 

六,dnf操作例子:对包的安装

1,安装

[root@blog ~]# dnf install zsh

 

2,从指定的repo安装一个rpm包

[root@blog ~]# dnf --enablerepo=BaseOS install zsh

 

3,仅下载,不安装

[root@blog ~]# dnf download nginx

下载完成后,可以在当前目录找到下载的rpm包

 

七,  dnf操作例子:对包的删除

1,删除指定的软件包

#remove:   删除指定的rpm包

[root@blog ~]# yum remove zsh

 

2,删除缓存的无用软件包

[root@blog ~]# dnf clean all 41 files removed

 

八,dnf操作例子:对包的更新

1,更新指定的软件包:

[root@blog ~]# dnf update zsh

 

2,更新所有的软件包:

[root@blog ~]# dnf update

也可以用upgrade

[root@blog ~]# dnf upgrade

 

3,检查可以更新的软件包

[root@blog ~]# dnf check-update

 

九,dnf操作例子:其他操作:

1,查看 DNF 命令的执行历史

[root@blog ~]# dnf history

 

2,查看某个指定命令的帮助

#help: 查看指定命令的帮助

[root@blog yum.repos.d]$ dnf help list

 

3,把软件包的元数据列表缓存到本地:

[root@centos8 yum.repos.d]# dnf makecache

 

十,如何编辑dnf的repo?

1,例子:修改dnf的repo使用国内源

Appstream库:

[root@centos8 yum.repos.d]# vi CentOS-AppStream.repo

修改baseurl一行为:

baseurl=https://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/

 

Base库:

[root@centos8 yum.repos.d]# vi CentOS-Base.repo

修改baseurl一行为:

baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/

 

Extras库:

[root@centos8 yum.repos.d]# vi CentOS-Extras.repo

修改baseurl一行为:

baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os/

 

以上修改完成后:

[root@centos8 yum.repos.d]# dnf clean all 51 文件已删除

更新缓存 

[root@centos8 yum.repos.d]# dnf makecache CentOS-8 - AppStream 3.8 MB/s | 6.6 MB 00:01 CentOS-8 - Base 2.8 MB/s | 5.0 MB 00:01 CentOS-8 - Extras 15 kB/s | 4.9 kB 00:00 Official OpenResty Open Source Repository for RHEL 158 kB/s | 38 kB 00:00

元数据缓存已建立。

查看BaseOS这个repo的信息

[root@centos8 yum.repos.d]# dnf repoinfo BaseOS 上次元数据过期检查:0:01:54 前,执行于 2020年04月13日 星期一 13时53分29秒。 仓库ID : BaseOS 仓库名 : CentOS-8 - Base 仓库状态 : 启用 仓库版本: 1585863557 仓库更新: 2020年04月03日 星期五 05时39分17秒 仓库包 : 2,126 仓库大小 : 1.9 G 仓库基本地址: https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/ 仓库到期: 172,800 秒 (最近 2020年04月13日 星期一 13时53分27秒) 仓库文件名: /etc/yum.repos.d/CentOS-Base.repo

 

执行一次安装,测试效果

[root@centos8 yum.repos.d]# yum install tmux

 

2,修改epel源也使用阿里云

安装epel源:

[root@centos8 yum.repos.d]# yum install epel-release

把源配置为阿里云

[root@centos8 yum.repos.d]# vi epel.repo

 

把epel段的baseurl一项修改为:

baseurl=http://mirrors.aliyun.com/epel/8/Everything/$basearch

并注释掉:metalink一项

[root@centos8 yum.repos.d]# dnf clean all 22 文件已删除

 

[root@centos8 yum.repos.d]# dnf makecache CentOS-8 - AppStream 2.4 MB/s | 6.6 MB 00:02 CentOS-8 - Base 2.7 MB/s | 5.0 MB 00:01 CentOS-8 - Extras 18 kB/s | 4.9 kB 00:00 Extra Packages for Enterprise Linux 8 - x86_64 5.1 MB/s | 6.2 MB 00:01 Official OpenResty Open Source Repository for RHEL 162 kB/s | 38 kB 00:00 元数据缓存已建立。

 

[root@centos8 yum.repos.d]# dnf repolist 上次元数据过期检查:0:00:09 前,执行于 2020年04月13日 星期一 14时07分30秒。 仓库标识 仓库名称 状态 AppStream CentOS-8 - AppStream 5,124 BaseOS CentOS-8 - Base 2,126 epel Extra Packages for Enterprise Linux 8 - x86_64 5,240 extras CentOS-8 - Extras 12 openresty Official OpenResty Open Source Repository for RHEL 83

 

[root@centos8 yum.repos.d]# dnf repoinfo epel 上次元数据过期检查:0:00:20 前,执行于 2020年04月13日 星期一 14时07分30秒。 仓库ID : epel 仓库名 : Extra Packages for Enterprise Linux 8 - x86_64 仓库状态 : 启用 仓库版本: 1586537550 仓库更新: 2020年04月11日 星期六 00时53分18秒 仓库包 : 5,240 仓库大小 : 6.5 G 仓库基本地址: http://mirrors.aliyun.com/epel/8/Everything/x86_64 仓库到期: 172,800 秒 (最近 2020年04月13日 星期一 14时07分26秒) 仓库文件名: /etc/yum.repos.d/epel.repo

 

测试epel源是否可用?

[root@centos8 yum.repos.d]# dnf install nethogs

 

十一,查看centos的版本 [root@centos8 yum.repos.d]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core)

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有