rpm的全称为The RPM Package Manager,是RHEL系操做系统的软件包管理器,这些软件包的后缀为.rpm。node
RPM命令用于在Linux系统上安装,卸载,升级,查询,列出和检查RPM软件包。算法
rpm -ivh PACKAGE_FILE ...
示例1:安装zsh软件包shell
[root@node1 ~]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:zsh-5.0.2-28.el7 ################################# [100%]
rpm -Uvh PACKAGE_FILE ... rpm -Fvh PACKAGE_FILE ...
-U,升级或安装,安装有旧版程序包,则升级,若是不存在旧版程序包,则安装。数据库
-F:升级,安装有旧版程序包,则升级,若是不存在旧版本程序包,则不执行升级操做。centos
示例2:将zsh软件包进行升级ide
[root@node1 ~]# rpm -Uvh zsh-5.0.2-34.el7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:zsh-5.0.2-34.el7 ################################# [ 50%] Cleaning up / removing... 2:zsh-5.0.2-28.el7 ################################# [100%]
rpm -e PACKAGE_NAME ...
示例3:卸载zsh软件包post
[root@node1 ~]# rpm -e zsh
示例4:使用 rpm -qa 查询当前系统上以rpm方式安装的全部软件包ui
[root@node1 ~]# rpm -qa plymouth-scripts-0.8.9-0.33.20140113.el7.centos.x86_64 grub2-common-2.02-0.81.el7.centos.noarch virt-what-1.18-4.el7.x86_64 setup-2.8.71-11.el7.noarch ...
示例5:使用 rpm -q 查询指定的软件包加密
[root@node1 ~]# rpm -q zsh zsh-5.0.2-34.el7.x86_64
示例6:使用 rpm -qf 查询指定的文件或目录是由哪一个软件包所安装的操作系统
[root@node1 ~]# rpm -qf /bin/ls coreutils-8.22-24.el7.x86_64
示例7:使用 rpm -qi 查询安装的软件包的信息
[root@node1 ~]# rpm -qi zsh Name : zsh Version : 5.0.2 Release : 34.el7 Architecture: x86_64 Install Date: Mon 18 May 2020 08:25:37 AM EDT Group : System Environment/Shells Size : 5856302 License : MIT Signature : RSA/SHA256, Fri 03 Apr 2020 05:10:32 PM EDT, Key ID 24c6a8a7f4a80eb5 Source RPM : zsh-5.0.2-34.el7.src.rpm Build Date : Tue 31 Mar 2020 09:31:30 PM EDT Build Host : x86-02.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem <http://bugs.centos.org> Vendor : CentOS URL : http://zsh.sourceforge.net/ Summary : Powerful interactive shell Description : The zsh shell is a command interpreter usable as an interactive login shell and as a shell script command processor. Zsh resembles the ksh shell (the Korn shell), but includes many enhancements. Zsh supports command line editing, built-in spelling correction, programmable command completion, shell functions (with autoloading), a history mechanism, and more.
示例8:使用 rpm -qc 查询指定的软件包在当前系统中安装的配置文件
[root@node1 ~]# rpm -qc zsh /etc/skel/.zshrc /etc/zlogin /etc/zlogout /etc/zprofile /etc/zshenv /etc/zshrc
示例9:使用 rpm -qd 查询指定的软件包在当前系统中安装的文档文件
[root@node1 ~]# rpm -qd zsh /usr/share/doc/zsh-5.0.2/BUGS /usr/share/doc/zsh-5.0.2/CONTRIBUTORS /usr/share/doc/zsh-5.0.2/FAQ /usr/share/doc/zsh-5.0.2/FEATURES /usr/share/doc/zsh-5.0.2/LICENCE ...
示例10:使用 rpm -ql 查询指定的软件包在当前系统中安装的全部目录
root@node1 ~]# rpm -ql zsh /bin/zsh /etc/skel/.zshrc /etc/zlogin /etc/zlogout /etc/zprofile /etc/zshenv /etc/zshrc /usr/lib64/zsh /usr/lib64/zsh/5.0.2
示例11:使用 rpm -qR 查询指定的软件包所依赖的软件包
[root@node1 ~]# rpm -qR zsh /bin/sh /bin/sh /bin/sh /bin/sh /bin/zsh /sbin/install-info /sbin/install-info config(zsh) = 5.0.2-34.el7_8.2 coreutils grep
示例12:使用 rpm -q --scripts 查询指定的软件包自带的脚本
[root@node1 ~]# rpm -q --scripts zsh postinstall scriptlet (using /bin/sh): if [ ! -f /etc/shells ] ; then echo "/bin/zsh" > /etc/shells else grep -q "^/bin/zsh$" /etc/shells || echo "/bin/zsh" >> /etc/shells fi ...
验证软件包会将软件包中已安装文件的信息与从rpm数据库中存储的软件包元数据中获取的文件的信息进行比较。
rpm -V PACKAGE_FILE ...
包来源合法性验证和完整性验证
软件包制做者首先使用单向加密算法,计算包的特征码,而后使用私钥加密特征码而后附加至软件包尾部,制做者的公钥须要让任何人都拿到,一般在发行光盘中都有公钥。软件安装者使用公钥对软件进行来源合法性验证和完整性验证。
获取并导入信任的包制做者的公钥:
对于CentOS发行版来讲
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
验证:
(1) 安装此组织签名的程序时,会自动执行验证;
(2) 手动验证:rpm -K PACKAGE_FILE
示例:以安装epel源中的fping软件为例,先不导入公钥。
[root@node1 ~]# wget https://mirror.tuna.tsinghua.edu.cn/epel/7/x86_64/Packages/f/fping-3.10-4.el7.x86_64.rpm [root@node1 ~]# rpm -ivh fping-3.10-4.el7.x86_64.rpm warning: fping-3.10-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:fping-3.10-4.el7 ################################# [100%]
示例:以安装epel源中的fping软件为例,导入公钥后再进行校验。
[root@node1 ~]# wget https://mirror.tuna.tsinghua.edu.cn/epel/RPM-GPG-KEY-EPEL-7 [root@node1 ~]# rpm --import RPM-GPG-KEY-EPEL-7 [root@node1 ~]# rpm -ivh fping-3.10-4.el7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:fping-3.10-4.el7 ################################# [100%]
示例:如何查看当前系统上已经导入的公钥。
[root@node1 ~]# rpm -q gpg-pubkey gpg-pubkey-352c64e5-52ae6884 gpg-pubkey-f4a80eb5-53a7ff4b
rpm包的数据库位于/var/lib/rpm目录中。
--initdb初始化,若是事先不存在数据库,则新建之,不然,不执行任何操做。
--rebuilddb:重建,不管当前存在与否,直接从新建立数据库。
[root@node1 ~]# ls /var/lib/rpm Basenames __db.001 __db.003 Group Name Packages Requirename Sigmd5 Conflictname __db.002 Dirnames Installtid Obsoletename Providename Sha1header Triggername