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