Home | 简体中文 | 繁体中文 | 杂文 | 知乎专栏 | Github | OSChina 博客 | 云社区 | 云栖社区 | Facebook | Linkedin | 视频教程 | 打赏(Donations) | About
知乎专栏多维度架构 微信号 netkiller-ebook | QQ群:128659835 请注明“读者”

6.3. DNF 包管理

6.3.1. 安装 epel-release 包

Extra Packages for Enterprise Linux repository configuration

使用下面命令安装企业版扩展包

		
dnf -y install epel-release		
		
		

安装演示

		
[root@localhost ~]# dnf search epel-release
Last metadata expiration check: 0:01:57 ago on Thu 05 Dec 2019 09:06:55 PM CST.
==================================================================================================== Name Exactly Matched: epel-release ====================================================================================================
epel-release.noarch : Extra Packages for Enterprise Linux repository configuration
[root@localhost ~]# 
[root@localhost ~]# dnf -y install epel-release
Last metadata expiration check: 0:02:41 ago on Thu 05 Dec 2019 09:06:55 PM CST.
Dependencies resolved.
============================================================================================================================================================================================================================================
 Package                                                      Arch                                                   Version                                                   Repository                                              Size
============================================================================================================================================================================================================================================
Installing:
 epel-release                                                 noarch                                                 8-5.el8                                                   extras                                                  22 k

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

Total download size: 22 k
Installed size: 30 k
Downloading Packages:
epel-release-8-5.el8.noarch.rpm                                                                                                                                                                              16 kB/s |  22 kB     00:01    
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                       7.5 kB/s |  22 kB     00:02     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                                                    1/1 
  Installing       : epel-release-8-5.el8.noarch                                                                                                                                                                                        1/1 
  Running scriptlet: epel-release-8-5.el8.noarch                                                                                                                                                                                        1/1 
  Verifying        : epel-release-8-5.el8.noarch                                                                                                                                                                                        1/1 

Installed:
  epel-release-8-5.el8.noarch                                                                                                                                                                                                               

Complete!
		
		
		

6.3.2. DNF 软件库管理

		
[root@localhost ~]# dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo	
		
		

6.3.3. 显示系统中可用的 DNF 软件库

		
[root@localhost ~]# dnf repolist
Last metadata expiration check: 0:00:25 ago on Sat 23 Nov 2019 11:06:18 AM EST.
repo id             repo name                                                 status
AppStream           CentOS-8 - AppStream                                      5,089
BaseOS              CentOS-8 - Base                                           2,843
*epel               Extra Packages for Enterprise Linux 8 - x86_64            3,328
extras              CentOS-8 - Extras                                             3
		
		
		
		
dnf repolist -v		
		
		

6.3.3.1. 查看系统中所有的 DNF 软件库(包括禁用状态)

		
[root@localhost ~]# dnf repolist all
Last metadata expiration check: 0:01:45 ago on Sat 23 Nov 2019 11:06:18 AM EST.
repo id                   repo name                                   status
AppStream                 CentOS-8 - AppStream                        enabled: 5,089
AppStream-source          CentOS-8 - AppStream Sources                disabled
BaseOS                    CentOS-8 - Base                             enabled: 2,843
BaseOS-source             CentOS-8 - BaseOS Sources                   disabled
PowerTools                CentOS-8 - PowerTools                       disabled
base-debuginfo            CentOS-8 - Debuginfo                        disabled
c8-media-AppStream        CentOS-AppStream-8 - Media                  disabled
c8-media-BaseOS           CentOS-BaseOS-8 - Media                     disabled
centosplus                CentOS-8 - Plus                             disabled
centosplus-source         CentOS-8 - Plus Sources                     disabled
cr                        CentOS-8 - cr                               disabled
*epel                     Extra Packages for Enterprise Linux 8 - x86 enabled: 3,328
epel-debuginfo            Extra Packages for Enterprise Linux 8 - x86 disabled
epel-playground           Extra Packages for Enterprise Linux 8 - Pla disabled
epel-playground-debuginfo Extra Packages for Enterprise Linux 8 - Pla disabled
epel-playground-source    Extra Packages for Enterprise Linux 8 - Pla disabled
epel-source               Extra Packages for Enterprise Linux 8 - x86 disabled
epel-testing              Extra Packages for Enterprise Linux 8 - Tes disabled
epel-testing-debuginfo    Extra Packages for Enterprise Linux 8 - Tes disabled
epel-testing-source       Extra Packages for Enterprise Linux 8 - Tes disabled
extras                    CentOS-8 - Extras                           enabled:     3
extras-source             CentOS-8 - Extras Sources                   disabled
fasttrack                 CentOS-8 - fasttrack                        disabled
		
		
			

6.3.4. 列出所有 RPM 包

用于列出系统上所有软件包

		
[root@localhost ~]# dnf list |more
Last metadata expiration check: 0:04:15 ago on Sat 23 Nov 2019 11:06:18 AM EST.
Installed Packages
GeoIP.x86_64                                         1.5.0-14.el7                                            @System      
NetworkManager.x86_64                                1:1.18.0-5.el7_7.1                                      @System      
NetworkManager-libnm.x86_64                          1:1.18.0-5.el7_7.1                                      @System      
NetworkManager-team.x86_64                           1:1.18.0-5.el7_7.1                                      @System      
NetworkManager-tui.x86_64                            1:1.18.0-5.el7_7.1                                      @System      
NetworkManager-wifi.x86_64                           1:1.18.0-5.el7_7.1                                      @System      
acl.x86_64                                           2.2.51-14.el7                                           @System      
adwaita-cursor-theme.noarch                          3.28.0-1.el7                                            @System      
adwaita-icon-theme.noarch                            3.28.0-1.el7                                            @System      
aic94xx-firmware.noarch                              30-6.el7                                                @System      
alsa-firmware.noarch                                 1.0.28-2.el7                                            @System      
alsa-lib.x86_64                                      1.1.8-1.el7                                             @System      
alsa-tools-firmware.x86_64                           1.1.0-1.el7                                             @System      
at-spi2-atk.x86_64                                   2.26.2-1.el7                                            @System      
at-spi2-core.x86_64                                  2.28.0-1.el7                                            @System      
atk.x86_64                                           2.28.1-1.el7                                            @System      
audit.x86_64                                         2.8.5-4.el7                                             @System      
audit-libs.x86_64                                    2.8.5-4.el7                                             @System      
audit-libs-python.x86_64                             2.8.5-4.el7                                             @System      
authconfig.x86_64                                    6.2.8-30.el7                                            @System      
autoconf.noarch                                      2.69-11.el7                                             @System      
--More--
		
		

列出制定包

		
[root@localhost ~]# dnf list nginx
Last metadata expiration check: 0:10:05 ago on Sat 23 Nov 2019 11:06:18 AM EST.
Available Packages
nginx.x86_64                                   1:1.14.1-9.module_el8.0.0+184+e34fea82                                   AppStream		
		
		

6.3.4.1. 查看已经安装包

用于列出系统上所有已经安装的软件包

		
[root@localhost ~]# dnf list installed | more
Installed Packages
GeoIP.x86_64                       1.5.0-14.el7                    @System      
NetworkManager.x86_64              1:1.18.0-5.el7_7.1              @System      
NetworkManager-libnm.x86_64        1:1.18.0-5.el7_7.1              @System      
NetworkManager-team.x86_64         1:1.18.0-5.el7_7.1              @System      
NetworkManager-tui.x86_64          1:1.18.0-5.el7_7.1              @System      
NetworkManager-wifi.x86_64         1:1.18.0-5.el7_7.1              @System      
acl.x86_64                         2.2.51-14.el7                   @System      
adwaita-cursor-theme.noarch        3.28.0-1.el7                    @System      
adwaita-icon-theme.noarch          3.28.0-1.el7                    @System      
aic94xx-firmware.noarch            30-6.el7                        @System      
alsa-firmware.noarch               1.0.28-2.el7                    @System      
alsa-lib.x86_64                    1.1.8-1.el7                     @System      
alsa-tools-firmware.x86_64         1.1.0-1.el7                     @System      
at-spi2-atk.x86_64                 2.26.2-1.el7                    @System      
at-spi2-core.x86_64                2.28.0-1.el7                    @System      
atk.x86_64                         2.28.1-1.el7                    @System      
audit.x86_64                       2.8.5-4.el7                     @System      
audit-libs.x86_64                  2.8.5-4.el7                     @System      
audit-libs-python.x86_64           2.8.5-4.el7                     @System      
authconfig.x86_64                  6.2.8-30.el7                    @System      
autoconf.noarch                    2.69-11.el7                     @System      
automake.noarch                    1.13.4-3.el7                    @System      
--More--
		
		
			

6.3.4.2. 列出可用的软件包

		
[root@localhost ~]# dnf list available | more
Last metadata expiration check: 0:07:35 ago on Sat 23 Nov 2019 11:06:18 AM EST.
Available Packages
3proxy.x86_64                                        0.8.13-1.el8                                            epel     
BackupPC.x86_64                                      4.3.1-3.el8                                             epel     
BackupPC-XS.x86_64                                   0.59-3.el8                                              epel     
CGSI-gSOAP.x86_64                                    1.3.11-7.el8                                            epel     
CGSI-gSOAP-devel.x86_64                              1.3.11-7.el8                                            epel     
CUnit.i686                                           2.1.3-17.el8                                            AppStream
CUnit.x86_64                                         2.1.3-17.el8                                            AppStream
Field3D.x86_64                                       1.7.2-16.el8                                            epel     
Field3D-devel.x86_64                                 1.7.2-16.el8                                            epel     
GConf2.i686                                          3.2.6-22.el8                                            AppStream
GConf2.x86_64                                        3.2.6-22.el8                                            AppStream
GraphicsMagick.x86_64                                1.3.33-1.el8                                            epel     
GraphicsMagick-c++.x86_64                            1.3.33-1.el8                                            epel     
GraphicsMagick-c++-devel.x86_64                      1.3.33-1.el8                                            epel     
GraphicsMagick-devel.x86_64                          1.3.33-1.el8                                            epel     
GraphicsMagick-doc.noarch                            1.3.33-1.el8                                            epel     
GraphicsMagick-perl.x86_64                           1.3.33-1.el8                                            epel     
HepMC.x86_64                                         2.06.10-1.el8                                           epel     
HepMC-devel.x86_64                                   2.06.10-1.el8                                           epel     
HepMC-doc.noarch                                     2.06.10-1.el8                                           epel     
HepMC3.x86_64                                        3.1.2-1.el8                                             epel     
--More--
		
		
			

6.3.4.3. 显示重复内容

		
dnf list docker-ce --showduplicates | sort -r
		
			

6.3.5. 搜索软件库中的包

		
[root@localhost ~]# dnf search mysql
Last metadata expiration check: 0:11:11 ago on Sat 23 Nov 2019 11:06:18 AM EST.
================================================= Name & Summary Matched: mysql =================================================
mysql.x86_64 : MySQL client programs and shared libraries
libnss-mysql.x86_64 : NSS library for MySQL
postfix-mysql.x86_64 : Postfix MySQL map support
rsyslog-mysql.x86_64 : MySQL support for rsyslog
collectd-mysql.x86_64 : MySQL plugin for collectd
libdbi-dbd-mysql.x86_64 : MySQL plugin for libdbi
dovecot-mysql.x86_64 : MySQL back end for dovecot
pdns-backend-mysql.x86_64 : MySQL backend for pdns
perl-DBD-MySQL.x86_64 : A MySQL interface for Perl
root-sql-mysql.x86_64 : MySQL client plugin for ROOT
freeradius-mysql.x86_64 : MySQL support for freeradius
voms-mysql-plugin.x86_64 : VOMS server plugin for MySQL
mysql-server.x86_64 : The MySQL server and related files
nagios-plugins-mysql.x86_64 : Nagios Plugin - check_mysql
zabbix40-web-mysql.noarch : Zabbix web frontend for MySQL
mysql-test.x86_64 : The test suite distributed with MySQL
python2-PyMySQL.noarch : Pure-Python MySQL client library
python3-PyMySQL.noarch : Pure-Python MySQL client library
apr-util-mysql.x86_64 : APR utility library MySQL DBD driver
qt5-qtbase-mysql.i686 : MySQL driver for Qt5's SQL classes
qt5-qtbase-mysql.x86_64 : MySQL driver for Qt5's SQL classes
rubygem-mysql2-doc.noarch : Documentation for rubygem-mysql2
zabbix40-proxy-mysql.x86_64 : Zabbix proxy compiled to use MySQL
mysql-devel.x86_64 : Files for development of MySQL applications
zabbix40-server-mysql.x86_64 : Zabbix server compiled to use MySQL
mysql-libs.x86_64 : The shared libraries required for MySQL clients
preludedb-mysql.x86_64 : Plugin to use prelude with a MySQL database
pcp-pmda-mysql.x86_64 : Performance Co-Pilot (PCP) metrics for MySQL
mysql-errmsg.x86_64 : The error messages files required by MySQL server
mysql80-community-release.noarch : MySQL repository configuration for yum
perl-DateTime-Format-MySQL.noarch : Parse and format MySQL dates and times
mysql-common.x86_64 : The shared files required for MySQL server and client
php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
mysql-community-client.x86_64 : MySQL database client applications and tools
rubygem-mysql2.x86_64 : A simple, fast Mysql library for Ruby, binding to libmysql
mysql-community-libs.x86_64 : Shared libraries for MySQL database client applications
mysql-community-common.x86_64 : MySQL database common files for server and client libs
lighttpd-mod_mysql_vhost.x86_64 : Virtual host module for lighttpd that uses a MySQL database
lighttpd-mod_authn_mysql.x86_64 : Authentication module for lighttpd that uses a MySQL database
mysql-community-libs-compat.x86_64 : Shared compat libraries for MySQL 5.6.45 database client applications
====================================================== Name Matched: mysql ======================================================
zabbix40-dbfiles-mysql.noarch : Zabbix database schemas, images, data and patches
==================================================== Summary Matched: mysql =====================================================
innotop.noarch : A MySQL and InnoDB monitor program
mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications
mariadb-server-utils.x86_64 : Non-essential server utilities for MariaDB/MySQL applications
mariadb-java-client.noarch : Connects applications developed in Java to MariaDB and MySQL databases
		
		

6.3.6. 查看软件包详情

		
[root@localhost ~]# dnf info redis
Last metadata expiration check: 0:13:10 ago on Sat 23 Nov 2019 11:06:18 AM EST.
Available Packages
Name         : redis
Version      : 5.0.3
Release      : 1.module_el8.0.0+6+ab019c03
Arch         : x86_64
Size         : 927 k
Source       : redis-5.0.3-1.module_el8.0.0+6+ab019c03.src.rpm
Repo         : AppStream
Summary      : A persistent key-value database
URL          : http://redis.io
License      : BSD and MIT
Description  : Redis is an advanced key-value store. It is often referred to as a data
             : structure server since keys can contain strings, hashes, lists, sets and
             : sorted sets.
             : 
             : You can run atomic operations on these types, like appending to a string;
             : incrementing the value in a hash; pushing to a list; computing set
             : intersection, union and difference; or getting the member with highest
             : ranking in a sorted set.
             : 
             : In order to achieve its outstanding performance, Redis works with an
             : in-memory dataset. Depending on your use case, you can persist it either
             : by dumping the dataset to disk every once in a while, or by appending
             : each command to a log.
             : 
             : Redis also supports trivial-to-setup master-slave replication, with very
             : fast non-blocking first synchronization, auto-reconnection on net split
             : and so forth.
             : 
             : Other features include Transactions, Pub/Sub, Lua scripting, Keys with a
             : limited time-to-live, and configuration settings to make Redis behave like
             : a cache.
             : 
             : You can use Redis from most programming languages also.
		
		

6.3.7. 查找某一文件的提供者

		
[root@localhost ~]# dnf provides /bin/bash
Last metadata expiration check: 0:11:58 ago on Sat 23 Nov 2019 11:06:18 AM EST.
bash-4.2.46-33.el7.x86_64 : The GNU Bourne Again shell
Repo        : @System
Matched from:
Provide    : /bin/bash

bash-4.4.19-7.el8.i686 : The GNU Bourne Again shell
Repo        : BaseOS
Matched from:
Provide    : /bin/bash

bash-4.4.19-7.el8.x86_64 : The GNU Bourne Again shell
Repo        : BaseOS
Matched from:
Provide    : /bin/bash

bash-4.4.19-8.el8_0.x86_64 : The GNU Bourne Again shell
Repo        : BaseOS
Matched from:
Provide    : /bin/bash
		
		
		

6.3.8. 删除软件包

		
[root@localhost ~]# dnf remove nginx