7.12 yum 的使用总结

只下载安装包

yumdownloader --destdir /home/wangbm/ perl-Sys-Virt.x86_64

下载安装包及其依赖包

yumdownloader --resolve --destdir /home/wangbm/ perl-Sys-Virt.x86_64
yumdownloader --resolve --destdir /home/test/ systemd-devel-219-62.el7_6.2.x86_64

查看一个包的安装时间

[root@ws_compute01 ~]# rpm -qi|grep zlib-1.2.7-17.el7.i686
rpm: no arguments given for query
[root@ws_compute01 ~]# rpm -qi zlib-1.2.7-17.el7.i686
Name        : zlib
Version     : 1.2.7
Release     : 17.el7
Architecture: i686
Install Date: Tue 13 Aug 2019 10:22:41 AM CST
Group       : System Environment/Libraries
Size        : 184798
License     : zlib and Boost
Signature   : RSA/SHA256, Mon 21 Nov 2016 05:05:03 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : zlib-1.2.7-17.el7.src.rpm
Build Date  : Sun 06 Nov 2016 02:07:22 AM CST
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.zlib.net/
Summary     : The compression and decompression library
Description :
Zlib is a general-purpose, patent-free, lossless data compression
library which is used by many different programs.

查看一个包在系统已配的源里都有哪些版本

[root@ws_compute01 ~]# yum provides
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
 * epel: hkg.mirror.rackspace.com
1:libguestfs-tools-1.28.1-1.55.el7.centos.noarch : System administration tools for virtual machines
Repo        : ansible-master


1:libguestfs-tools-1.28.1-1.55.el7.centos.noarch : System administration tools for virtual machines
Repo        : libvirt-3.9.0


1:libguestfs-tools-1.28.1-1.55.el7.centos.noarch : System administration tools for virtual machines
Repo        : wsbase


1:libguestfs-tools-1.38.2-12.el7.noarch : System administration tools for virtual machines
Repo        : ansible-master


1:libguestfs-tools-1.38.2-12.el7.noarch : System administration tools for virtual machines
Repo        : libvirt-4.5.0


1:libguestfs-tools-1.38.2-12.el7.noarch : System administration tools for virtual machines
Repo        : wsupdates


1:libguestfs-tools-1.38.2-12.el7.noarch : System administration tools for virtual machines
Repo        : @libvirt-4.5.0

yum-utils 使用

$ yum install yum-utils

# 清理未完成的yum事务
$ yum-complete-transaction --cleanup-only

# 清除可能存在的重复包
$ package-cleanup --dupes

# 清除可能存在的损坏包
$ package-cleanup --problems
glibc-common-2.17-196.el7_4.2.x86_64 has missing requires of glibc = ('0', '2.17', '196.el7_4.2')
# 将上面列出的包卸载
$ rpm -e glibc-common-2.17-196.el7_4.2.x86_64

查找一个 so 文件是属于哪个 rpm 包

经常在安装一个包的时候,会报如下的错误,找不到某 so 文件

image0

如果是缺一个包,那我们安装它就行了,缺 so 文件,那咋弄?

首先我们要找到有这个 so 文件的机器,然后可以用 yum 提供的工具来获取其所属的 rpm 包 ,然后安装这个包即可。

$ yum whatprovides /usr/lib64/libpcap.so.1
...
14:libpcap-1.5.3-8.el7.x86_64 : A system-independent interface for user-level packet capture
Repo        : @anaconda
Matched from:
Filename    : /usr/lib64/libpcap.so.1.5.3

$ yum install libpcap

查看某个包的安装历史

# 查该包所有的安装历史
$ yum history list python-nova-tests

# 只能查已安装的包的安装日期。截图中,之所以存在两个包,是因为该机器上存在两个版本的包
$ rpm -qa --last | grep python-nova-tests

image1

查看安装某个包是如何安装的,从哪安装

$ yumdb info python-nova-tests

image2

查看rpm包的版本

# 查看软件包的详细信息
rpm -qpi xxx.rpm

# 查看软件包所包含的目录和文件
rpm -qpl xxx.rpm

# 查看软件包的文档所在的位置
rpm -qpd xxx.rpm

# 查看软件包的配置文件
rpm -qpc rpm

# 查看软件包的依赖关系
rpm -qpR xxx.rpm