一,dnf的用途
centos7開始,DNF 成為了默認的軟件包管理器,同時 yum 仍然是可用的
DNF包管理器克服了YUM包管理器的一些瓶頸,提升了用戶體驗,內存占用,依賴分析,運行速度等方面
DNF使維護軟件包組變得容易,並且能夠自動解決依賴性問題
說明:劉宏締的架構森林是一個專注架構的博客,地址:https://www.cnblogs.com/architectforest
對應的源碼可以訪問這里獲取: https://github.com/liuhongdi/
說明:作者:劉宏締 郵箱: 371125307@qq.com
二,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 <bugs@centos.org> 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 <bugs@centos.org> 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)