【命令星级】 ★★★★★
【功能说明】
rpm命令的全称是Red Hat Package Manager(Red Hat包管理器),几乎所有的Linux发行版都使用了这种形式的命令管理、安装、更新和卸载软件。
概括地说,rpm命令包含了五种基本功能(不包括创建rpm包):安装、卸载、升级、查询和验证。
【语法格式】
rpm [option]
rpm [选项]
**说明:**在rpm命令及后面的选项里,每个元素之间都至少要有一个空格。
【选项说明】
表11-16针对该命令的参数选项进行了说明。
表11-16 rpm命令的参数选项及说明

【示例准备】
下载一个RPM包作为测试文件:
[root@centos7 ~]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/lrzsz-0.12.20-36.el7.x86_64.rpm
**范例11-47:**查看rpm包信息。
[root@centos7 ~]# rpm -qpi lrzsz-0.12.20-36.el7.x86_64.rpm #显示rpm包的版本,创建日期等信息。
Name : lrzsz
Version : 0.12.20
Release : 36.el7
Architecture: x86_64
Install Date: (not installed)
Group : Applications/Communications
Size : 184846
License : GPLv2+
Signature : RSA/SHA256, Fri 04 Jul 2014 11:35:32 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM : lrzsz-0.12.20-36.el7.src.rpm
Build Date : Tue 10 Jun 2014 07:29:11 AM CST
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://www.ohse.de/uwe/software/lrzsz.html
Summary : The lrz and lsz modem communications programs
Description :
Lrzsz (consisting of lrz and lsz) is a cosmetically modified
zmodem/ymodem/xmodem package built from the public-domain version of
the rzsz package. Lrzsz was created to provide a working GNU
copylefted Zmodem solution for Linux systems.
**范例11-48:**查看rpm包内容。
[root@centos7 ~]# rpm -qpl lrzsz-0.12.20-36.el7.x86_64.rpm
/usr/bin/rb
/usr/bin/rx
/usr/bin/rz
/usr/bin/sb
/usr/bin/sx
/usr/bin/sz
/usr/share/locale/de/LC_MESSAGES/lrzsz.mo
/usr/share/man/man1/rz.1.gz
/usr/share/man/man1/sz.1.gz
**范例11-49:**查看rpm包的依赖。
[root@centos7 ~]# rpm -qpR lrzsz-0.12.20-36.el7.x86_64.rpm #查看安装此rpm包需要依赖的文件。
libc.so.6()(64bit)
libc.so.6(GLIBC_2.11)(64bit)
libc.so.6(GLIBC_2.14)(64bit)
libc.so.6(GLIBC_2.15)(64bit)
libc.so.6(GLIBC_2.2.5)(64bit)
libc.so.6(GLIBC_2.3)(64bit)
libc.so.6(GLIBC_2.3.4)(64bit)
libc.so.6(GLIBC_2.4)(64bit)
libc.so.6(GLIBC_2.7)(64bit)
libnsl.so.1()(64bit)
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PartialHardlinkSets) <= 4.0.4-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rtld(GNU_HASH)
rpmlib(PayloadIsXz) <= 5.2-1
**范例11-50:**安装rpm包。
[root@centos7 ~]# rpm -ivh lrzsz-0.12.20-36.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:lrzsz-0.12.20-36.el7 ################################# [100%]
#rpm还支持在线安装,直接接一个URL地址 rpm -ivh https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/lrzsz-0.12.20-36.el7.x86_64.rpm
**范例11-51:**查询系统是否安装指定的rpm包。
[root@centos7 ~]# rpm -qa lrzsz #这里没有使用-p参数,因为lrzsz是软件名,没有以“.rpm”结尾。
lrzsz-0.12.20-36.el7.x86_64
**范例11-52:**卸载rpm包。
[root@centos7 ~]# rpm -e lrzsz #卸载软件包使用-e参数,这个参数比较危险,一般情况下若没有必要则尽量不要去卸载软件包,因为很有可能会误删除一些系统必备的软件,最后导致系统损坏。
[root@centos7 ~]# rpm -qa lrzsz #再次查看,软件已经卸载了。
**范例11-53:**查询文件属于哪个rpm包。
[root@centos7 ~]# rpm -qf $(which ifconfig) #有时候会发现系统没有某些文件或者命令,但是又不知道这个文件或命令是属于哪个软件包,这时就可以使用-f参数来查询(在有这个文件的系统上查询)。比如本例查询ifconfig命令属于net-tools软件包。
net-tools-2.0-0.25.20131004git.el7.x86_64
【命令星级】 ★★★★★
【功能说明】
yum(Yellow dog Updater Modified)是多个Linux发行版的软件包管理器,例如Redhat RHEL、CentOS和Fedora。yum主要用于自动安装、升级rpm软件包,它能自动查找并解决rpm包之间的依赖关系。
【语法格式】
yum [option] [command] [package]
yum [选项] [指令] [软件包]
**说明:**在yum命令及后面的选项里,每个元素之间都至少要有一个空格。
【选项说明】
表11-17针对该命令的参数选项进行了说明。
表11-17 yum命令的参数选项及说明


下面以httpd软件包为例,给出常用的yum命令,见表11-18.
表11-18 yum命令常用功能

**范例11-54:**安装httpd软件包。
[root@centos7 ~]# yum install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-93.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-93.el7.centos for package: httpd-2.4.6-93.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-93.el7.centos.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-93.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================
Package Arch Version Repository
Size
====================================================================
Installing:
httpd x86_64 2.4.6-93.el7.centos base 2.7 M
Installing for dependencies:
httpd-tools x86_64 2.4.6-93.el7.centos base 92 k
mailcap noarch 2.1.41-2.el7 base 31 k
Transaction Summary
====================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 2.8 M
Installed size: 9.6 M
Is this ok [y/d/N]: y #如果执行命令不加-y选项,那么此处就需要输入y来确认安装,N表示不安装。
Downloading packages:
(1/3): httpd-tools-2.4.6-93.el7.centos.x86_64. | 92 kB 00:00
(2/3): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00
(3/3): httpd-2.4.6-93.el7.centos.x86_64.rpm | 2.7 MB 00:00
--------------------------------------------------------------------
Total 3.4 MB/s | 2.8 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mailcap-2.1.41-2.el7.noarch 1/3
Installing : httpd-tools-2.4.6-93.el7.centos.x86_64 2/3
Installing : httpd-2.4.6-93.el7.centos.x86_64 3/3
Verifying : httpd-tools-2.4.6-93.el7.centos.x86_64 1/3
Verifying : mailcap-2.1.41-2.el7.noarch 2/3
Verifying : httpd-2.4.6-93.el7.centos.x86_64 3/3
Installed:
httpd.x86_64 0:2.4.6-93.el7.centos
Dependency Installed:
httpd-tools.x86_64 0:2.4.6-93.el7.centos
mailcap.noarch 0:2.1.41-2.el7
Complete!
**范例11-55:**常见yum命令的例子。
[root@centos7 ~]# yum list httpd #检查httpd安装列表
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Installed Packages
httpd.x86_64 2.4.6-93.el7.centos @base
[root@centos7 ~]# yum search httpd #搜索包含httpd字符串的软件包。
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
======================== N/S matched: httpd ========================
dmlite-apache-httpd.x86_64 : Apache HTTPD frontend for dmlite
iipsrv-httpd-fcgi.noarch : Apache HTTPD files for iipsrv
keycloak-httpd-client-install.noarch : Tools to configure Apache
: HTTPD as Keycloak client
libmicrohttpd-devel.i686 : Development files for libmicrohttpd
libmicrohttpd-devel.x86_64 : Development files for libmicrohttpd
libmicrohttpd-doc.noarch : Documentation for libmicrohttpd
lighttpd-fastcgi.x86_64 : FastCGI module and spawning helper for
: lighttpd and PHP configuration
lighttpd-mod_authn_gssapi.x86_64 : Authentication module for
: lighttpd that uses GSSAPI
lighttpd-mod_authn_mysql.x86_64 : Authentication module for lighttpd
: that uses a MySQL database
lighttpd-mod_authn_pam.x86_64 : Authentication module for lighttpd
: that uses PAM
lighttpd-mod_geoip.x86_64 : GeoIP module for lighttpd to use for
: location lookups
lighttpd-mod_mysql_vhost.x86_64 : Virtual host module for lighttpd
: that uses a MySQL database
owncloud-httpd.noarch : Httpd integration for ownCloud
pagure-web-apache-httpd.noarch : Apache HTTPD configuration for
: Pagure
python2-keycloak-httpd-client-install.noarch : Tools to configure
...: Apache HTTPD as Keycloak client
radicale-httpd.noarch : httpd config for Radicale
sympa-lighttpd.x86_64 : Sympa with lighttpd
darkhttpd.x86_64 : A secure, lightweight, fast, single-threaded
: HTTP/1.1 server
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP
: server
httpd-itk.x86_64 : MPM Itk for Apache HTTP Server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
libmicrohttpd.i686 : Lightweight library for embedding a webserver
: in applications
libmicrohttpd.x86_64 : Lightweight library for embedding a webserver
: in applications
lighttpd.x86_64 : Lightning fast webserver with light system
: requirements
mirmon-httpd.noarch : Apache configuration for mirmon
mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the
: Apache Httpd Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server
opensips-httpd.x86_64 : HTTP transport layer implementation
perl-Test-Fake-HTTPD.noarch : Fake HTTP server module for testing
python2-sphinxcontrib-httpdomain.noarch : Sphinx domain for
: documenting HTTP APIs
sympa-httpd.x86_64 : Sympa with Apache HTTP Server
sysusage-httpd.noarch : Apache configuration for sysusage
thttpd.x86_64 : A tiny, turbo, throttleable lightweight HTTP server
viewvc-httpd-fcgi.noarch : ViewVC configuration for Apache/mod_fcgid
viewvc-httpd-wsgi.noarch : ViewVC configuration for Apache/mod_wsgi
web-assets-httpd.noarch : Web Assets aliases for the Apache HTTP
: daemon
Name and summary matches only, use "search all" for everything.
[root@centos7 ~]# yum grouplist #查看已安装和未安装的包组。
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Available Environment Groups:
Minimal Install
Compute Node
Infrastructure Server
File and Print Server
Cinnamon Desktop
MATE Desktop
Basic Web Server
Virtualization Host
Server with GUI
GNOME Desktop
KDE Plasma Workspaces
Development and Creative Workstation
Installed Groups:
Compatibility Libraries
Development Tools
Milkymist
Security Tools
System Administration Tools
Available Groups:
Cinnamon
Console Internet Tools
Educational Software
Electronic Lab
Fedora Packager
General Purpose Desktop
Graphical Administration Tools
Haskell
LXQt Desktop
Legacy UNIX Compatibility
MATE
Scientific Support
Smart Card Support
System Management
TurboGears application framework
Xfce
Done
[root@centos7 ~]# yum groupinstall "GNOME Desktop" -y #安装包组,从yum grouplist中查找。