811 瀏覽數

Linux – dnf

測試環境 CentOS7

套件管理從最早的 Red Hat Package Manager (#rpm) , 到現在常用的 Yellowdog Updater, Modified (#yum) 現在 Fedora 22 改成 DNF : Dandified Yum (#dnf) 為預設的套件管理工具.

wiki:
DNF is intended to address include poor performance, high memory usage, and the slowness of its iterative dependency resolution. DNF uses libsolv, an external dependency resolver.

因為遇到一個套件一定要用 dnf 來安裝,所以試著在 CentOS7 下來使用 dnf ,YUM 預設並沒有 dnf ,所以我們需要手動新增 dnf 的 Repo 檔 (epel-release) ,或是手動編寫 /etc/yum.repos.d/epel.repo .

[root@localhost ~]# yum install epel-release
Loaded plugins: fastestmirror
base                                                     | 3.6 kB     00:00     
extras                                                   | 3.4 kB     00:00     
nginx                                                    | 2.9 kB     00:00     
updates                                                  | 3.4 kB     00:00     
Loading mirror speeds from cached hostfile
 * base: centos.cs.nctu.edu.tw
 * extras: centos.cs.nctu.edu.tw
 * updates: centos.cs.nctu.edu.tw
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch             Version         Repository        Size
================================================================================
Installing:
 epel-release           noarch           7-6             extras            14 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 14 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-6.noarch.rpm                                |  14 kB   00:06     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-6.noarch                                      1/1 
  Verifying  : epel-release-7-6.noarch                                      1/1 

Installed:
  epel-release.noarch 0:7-6                                                     

Complete!
[root@localhost ~]# cd /etc/yum.repos.d/epel.repo 
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

現在就可以直接透過 yum 安裝 dnf

[root@localhost ~]# yum install dnf
Loaded plugins: fastestmirror
epel/x86_64/metalink                                     | 4.8 kB     00:00     
epel                                                     | 4.3 kB     00:00     
(1/3): epel/x86_64/updateinfo                              | 678 kB   00:01     
(2/3): epel/x86_64/group_gz                                | 170 kB   00:02     
(3/3): epel/x86_64/primary_db                              | 4.3 MB   00:11     
Loading mirror speeds from cached hostfile
 * base: centos.cs.nctu.edu.tw
 * epel: mirror01.idc.hinet.net
 * extras: centos.cs.nctu.edu.tw
 * updates: centos.cs.nctu.edu.tw
Resolving Dependencies
...
Dependencies Resolved
================================================================================
 Package                 Arch      Version                        Repository
                                                                           Size
================================================================================
Installing:
 dnf                     noarch    0.6.4-2.el7                    epel    209 k
Installing for dependencies:
 deltarpm                x86_64    3.6-3.el7                      base     82 k
 dnf-conf                noarch    0.6.4-2.el7                    epel     61 k
 hawkey                  x86_64    0.5.8-2.git.0.202b194.el7      base     87 k
 libcomps                x86_64    0.1.6-13.el7                   epel     72 k
 librepo                 x86_64    1.7.16-1.el7                   base     77 k
 libreport-filesystem    x86_64    2.1.11-32.el7.centos           base     37 k
 libsolv                 x86_64    0.6.11-1.el7                   base    316 k
 python-dnf              noarch    0.6.4-2.el7                    epel    407 k
 python-hawkey           x86_64    0.5.8-2.git.0.202b194.el7      base     71 k
 python-libcomps         x86_64    0.1.6-13.el7                   epel     44 k
 python-librepo          x86_64    1.7.16-1.el7                   base     49 k

Transaction Summary
================================================================================
Install  1 Package (+11 Dependent packages)
...
...

使用可以直接參考 dnf 的說明.

[root@localhost ~]# dnf
You need to give some command
usage: dnf [options] COMMAND

List of Main Commands

autoremove                
check-update              Check for available package upgrades
clean                     Remove cached data
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
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
repository-packages       Run commands on top of all packages in given repository
search                    Search package details for the given string
updateinfo                Display advisories about packages
upgrade                   Upgrade a package or packages on your system
upgrade-to                Upgrade a package on your system to the specified version

遇過的問題
CentOS7 ARM 系統透過 yum 找不到 epel-release,只能透過 wget 再手動 rpm.

[root@localhost ~]# yum install epel-release
...No package epel-release available
Error: Nothing to do
[root@localhost ~]# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@localhost ~]# rpm -Uvh epel-release-latest-7*.rpm

安裝完 dnf 初次會遇到類似下方的錯誤訊息,需要移除 epel-release 並執行 dnf repolist

[root@localhost ~]# dnf repolist
Extra Packages for Enterprise Linux 7 - x86_64  616 kB/s |  12 MB     00:19    
Failed to open: /var/cache/dnf/x86_64/7/x86_64/7/epel/repodata/a2cc7cbec8f5f02226dc6590b7a6ed439ae7324e9fa52b70e303470895d08066-updateinfo.xml.bz2.
[root@localhost ~]# yum remove epel-release
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-6 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch             Version        Repository         Size
================================================================================
Removing:
 epel-release           noarch           7-6            @extras            24 k

Transaction Summary
================================================================================
Remove  1 Package

Installed size: 24 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : epel-release-7-6.noarch                                      1/1 
  Verifying  : epel-release-7-6.noarch                                      1/1 

Removed:
  epel-release.noarch 0:7-6                                                     

Complete!
[root@localhost ~]# dnf repolist
CentOS-7 - Base                                 893 kB/s | 8.8 MB     00:10    
CentOS-7 - Updates                              1.4 MB/s |  12 MB     00:08    
CentOS-7 - Extras                               750 kB/s | 569 kB     00:00    
Using metadata from Wed Nov 23 20:41:50 2016
repo id                        repo name                                  status
base                           CentOS-7 - Base                            9,007
extras                         CentOS-7 - Extras                            393
nginx                          nginx repo                                    41
updates                        CentOS-7 - Updates                         2,560

網友的想法

  1. 自動參照通知: ARM KVM (CentOS) – Benjr.tw

發表迴響