Linux下的RPM命令及其示例
RPM(Redhat Package Manager)是用于安装,卸载,更新,查询和验证软件包的命令行包管理实用程序。
本教程我将解释系统管理员的一些最常见的Linux RPM命令。
基于RPM的Linux Distras是Redhat,CentOS,Fedora和OpenSuse。
YUM和DNF是用于RPM管理的前端,具有更多功能,可以克服它的限制。
如何获得RPM软件包
如下所示,有几种方法可用于获取RPM包。
- 软件CD/DVD
- CentOS镜子
- Redhat(需要帐户)
- 任何开放存储库
RPM命令的基本模式
- 安装:它用于安装任何RPM包。
- 删除:它用于擦除,删除或者取消安装任何RPM包。
- 升级:它用于更新现有的RPM包。
- 查询:它用于查询任何RPM包。
- 验证:它用于验证RPM包。
RPM包的示例
GeoIP应用程序GeoIP-1.5.0-11.el7.x86_64.rpm
是一个国家/地区/组织到IP地址或者主机名映射的RPM包库。GeoIP
是包名称,版本为"1.5.0-11.el7"",释放是"7"和"建筑".X86_64"。
安装
1)如何知道RPM包的信息而不安装
我们下载了一个包后,我们想在安装之前了解包的信息。
我们可以使用-qip
选项(查询信息包)列出包的信息。
$sudo rpm -qip GeoIP-1.5.0-11.el7.x86_64.rpm
output Name : GeoIP Version : 1.5.0 Release : 11.el7 Architecture: x86_64 Install Date: (not installed) Group : Development/Libraries Size : 2905020 License : LGPLv2+ and GPLv2+ and CC-BY-SA Signature : RSA/SHA256, Sun 20 Nov 2015 05:49:19 PM UTC, Key ID 24c6a8a7f4a80eb5 Source RPM : GeoIP-1.5.0-11.el7.src.rpm Build Date : Sat 05 Nov 2015 08:29:17 PM UTC Build Host : worker1.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem Vendor : CentOS URL : http://www.maxmind.com/app/c Summary : Library for country/city/organization to IP address or hostname mapping Description : GeoIP is a C library that enables the user to find the country that any IP address or hostname originates from. It uses a file based database that is accurate as of June 2007 and can optionally be updated on a weekly basis by installing the GeoIP-update package. This database simply contains IP blocks as keys, and countries as values. This database should be more complete and accurate than using reverse DNS lookups. This package includes GeoLite data created by MaxMind, available from http://www.maxmind.com/
2)如何安装RPM包
我们可以使用"-ivh"参数来安装特定的包,如下所示。
$sudo rpm -ivh GeoIP-1.5.0-11.el7.x86_64.rpm
Output Preparing... ################################# [100%] package GeoIP-1.5.0-11.el7.x86_64 is already installed
3)如何检查安装的RPM包
我们可以使用包名称的"-Q"选项,它将显示是否安装了RPM包。
$sudo rpm -q GeoIP
output GeoIP-1.5.0-11.el7.x86_64
4)如何列出特定安装的RPM包的所有文件
我们可以使用使用rpm命令的-ql
选项列出已安装的RPM包的所有文件。
$sudo rpm -ql GeoIP
output /etc/GeoIP.conf /etc/GeoIP.conf.default /usr/bin/geoiplookup /usr/bin/geoiplookup6 /usr/bin/geoipupdate /usr/lib64/libGeoIP.so.1 /usr/lib64/libGeoIP.so.1.5.0 /usr/lib64/libGeoIPUpdate.so.0 /usr/lib64/libGeoIPUpdate.so.0.0.0 /usr/share/GeoIP /usr/share/GeoIP/GeoIP-initial.dat /usr/share/GeoIP/GeoIP.dat /usr/share/GeoIP/GeoIPASNum.dat /usr/share/GeoIP/GeoIPASNumv6.dat /usr/share/GeoIP/GeoIPCity.dat /usr/share/GeoIP/GeoIPCityv6.dat /usr/share/GeoIP/GeoIPCountry.dat /usr/share/GeoIP/GeoIPCountryv6.dat /usr/share/GeoIP/GeoIPv6-initial.dat ...
5)如何列出最近安装的RPM包
我们可以使用"-qa""选项使用"--last",它将列出所有最近安装的RPM包。
$sudo rpm -qa --last
output GeoIP-1.5.0-11.el7.x86_64 Sat 01 Sep 2016 11:34:09 AM UTC wget-1.14-15.el7_4.1.x86_64 Sun 26 Aug 2016 03:21:02 PM UTC iwl7265-firmware-22.0.7.0-62.2.el7_5.noarch Thu 16 Aug 2016 02:10:18 PM UTC libgomp-4.8.5-28.el7_5.1.x86_64 Thu 16 Aug 2016 02:10:15 PM UTC iwl2030-firmware-18.168.6.1-62.2.el7_5.noarch Thu 16 Aug 2016 02:10:15 PM UTC iptables-1.4.21-24.1.el7_5.x86_64 Thu 16 Aug 2016 02:10:15 PM UTC yum-plugin-fastestmirror-1.1.31-46.el7_5.noarch Thu 16 Aug 2016 02:10:14 PM UTC iwl6000-firmware-9.221.4.1-62.2.el7_5.noarch Thu 16 Aug 2016 02:10:14 PM UTC iwl4965-firmware-228.61.2.24-62.2.el7_5.noarch Thu 16 Aug 2016 02:10:14 PM UTC iwl105-firmware-18.168.6.1-62.2.el7_5.noarch Thu 16 Aug 2016 02:10:14 PM UTC iwl100-firmware-39.31.5.1-62.2.el7_5.noarch Thu 16 Aug 2016 02:10:13 PM UTC iwl1000-firmware-39.31.5.1-62.2.el7_5.noarch Thu 16 Aug 2016 02:10:13 PM UTC ca-certificates-2016.2.22-70.0.el7_5.noarch Thu 16 Aug 2016 02:10:13 PM UTC iwl6000g2b-firmware-17.168.5.2-62.2.el7_5.noarch Thu 16 Aug 2016 02:10:12 PM UTC ...
6)如何在没有依赖项的情况下安装RPM包
我们可以使用" - " - " - " - " - " - " - " - " - " - " - " - " - 不依赖关系"选项,以安装特定的包,无需依赖项,如下所示。
$sudo rpm -ivh --nodeps GeoIP-1.5.0-11.el7.x86_64.rpm
Output Preparing... ################################# [100%] package GeoIP-1.5.0-11.el7.x86_64 is already installed
7)如何更换安装RPM包
我们可以使用ivh --replacepkgs
参数来更换如下所示安装的特定包。
$sudo rpm -ivh --replacepkgs GeoIP-1.5.0-11.el7.x86_64.rpm
Output Preparing... ################################# [100%] Updating/installing... 1:GeoIP-1.5.0-11.el7 ################################# [100%]
去掉
8)如何卸载RPM包
我们可以使用-e
参数卸载特定包,而不依赖于依赖项(不检查依赖项),如下所示。
$sudo rpm -e --nodeps GeoIP
现在键入下面的命令,以确保未安装GeoIP。
$sudo rpm -q GeoIP
Output package GeoIP is not installed
升级
9)安装了如何升级RPM包
我们可以使用"-uvh"参数来升级所安装的特定包,如下所示。
$sudo rpm -Uvh GeoIP-1.5.0-11.el7.x86_64.rpm
Output Preparing... ################################# [100%] package GeoIP-1.5.0-11.el7.x86_64 is already installed
询问
10)如何查询所有已安装的包
我们可以使用-a
参数以及q
查询服务器上的所有已安装的软件包,如下所示。
$sudo rpm -qa
Output python-firewall-0.4.4.4-14.el7.noarch ncurses-base-5.9-14.20130511.el7_4.noarch plymouth-0.8.9-0.31.20140113.el7.centos.x86_64 kbd-misc-1.15.5-13.el7.noarch vim-common-7.4.160-4.el7.x86_64 bash-4.2.46-30.el7.x86_64 dmidecode-3.0-5.el7.x86_64 filesystem-3.2-25.el7.x86_64 kbd-1.15.5-13.el7.x86_64 vim-enhanced-7.4.160-4.el7.x86_64 firewalld-0.4.4.4-14.el7.noarch ....
11)如何查询特定包
我们可以使用Grep
命令找到一个特定包装安装或者不如下所示。
$sudo rpm -qa | grep GeoIP
Output GeoIP-1.5.0-11.el7.x86_64
12)如何查询属于哪些RPM包的文件
在示例号9我们键入命令以列出已安装的rpm包的所有文件,现在我们想知道/usr/lib64/libgeoip.so.1.5.0
文件属于哪种RPM包。
$sudo rpm -qf /usr/lib64/libGeoIP.so.1.5.0
output GeoIP-1.5.0-11.el7.x86_64
核实
13)如何获取特定包的信息
我们可以使用-i
参数以及q
获取特定包的信息,如下所示。
$sudo rpm -qi GeoIP
Output Name : GeoIP Version : 1.5.0 Release : 11.el7 Architecture: x86_64 Install Date: Thu 16 Aug 2016 02:04:09 PM UTC Group : Development/Libraries Size : 2905020 License : LGPLv2+ and GPLv2+ and CC-BY-SA Signature : RSA/SHA256, Sun 20 Nov 2015 05:49:19 PM UTC, Key ID 24c6a8a7f4a80eb5 Source RPM : GeoIP-1.5.0-11.el7.src.rpm Build Date : Sat 05 Nov 2015 08:29:17 PM UTC Build Host : worker1.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem Vendor : CentOS URL : http://www.maxmind.com/app/c Summary : Library for country/city/organization to IP address or hostname mapping Description : GeoIP is a C library that enables the user to find the country that any IP address or hostname originates from. It uses a file based database that is accurate as of June 2007 and can optionally be updated on a weekly basis by installing the GeoIP-update package. This database simply contains IP blocks as keys, and countries as values. This database should be more complete and accurate than using reverse DNS lookups. This package includes GeoLite data created by MaxMind, available from http://www.maxmind.com/
14)如何验证RPM包
我们可以通过使用"-vp"选项(验证包)将包的已安装文件的信息与RPM数据库进行比较来验证包。
$sudo rpm -Vp GeoIP-1.5.0-11.el7.x86_64.rpm
15)如何验证所有RPM包
我们可以使用"-VA"选项(验证全部)验证所有已安装的RPM包。
$sudo rpm -Va
output S.5....T. c /etc/sysconfig/authconfig S.5....T. c /etc/yum.repos.d/CentOS-Base.repo .M....... c /etc/machine-id .M....... g /etc/udev/hwdb.bin .M....... g /var/lib/systemd/random-seed .M....... c /etc/shadow S.5....T. c /etc/ssh/sshd_config .M....... c /etc/audit/rules.d/audit.rules S.5....T. c /etc/NetworkManager/NetworkManager.conf ....L.... c /etc/pam.d/fingerprint-auth ....L.... c /etc/pam.d/password-auth ....L.... c /etc/pam.d/postlogin ...