最後更新: 2020-06-02
介紹
rpm cmd 除了有 installing, uninstalling, upgrading 的功用外,
它還有 querying, verifying package 的功能
目錄
- 安裝 / 移除
- 升級 / 安裝
- Query
- Verify
- RPM-GPG-KEY
- RPM Database Recovery
- rpm -qa without package version
- To extract file from rpm file(rpm2cpio)
安裝 Package
rpm -i package.rpm // 安裝 foo
rpm -ivh package.rpm // show '#' 及有資料
移除 Package
rpm -e package
rpm --nodeps -e foo // 不理會 depence 去移除 foo
Simulate
rpm -ivh --test new-kernel.rpm
- -v: verbose
- -h: progress meter
Upgrade
rpm -Uvh package.rpm // -U 除了升級外, 同時有 install 的意思, 它幾乎可以取代 "-i"
rpm -Uvh --replacepkgs kernel_package.rpm // 有取代原本設定檔的作用, 並且包有 --force 的作用
rpm -Uvh pack1.rpm dep.rpm // 解決 Dependency
Downgrade
rpm -Uvh --oldpackage package.rpm // 還原到之前版本
Query
一切數據斬是由 RPM database ( /var/lib/rpm/) 提供
rpm -q --whatprovides libcrypt.so.1
rpm -p <package_file> // Query an (uninstalled) package PACKAGE_FILE
rpm -q <package_file>
rpm -qi <package_file> // information
rpm -ql <package_name> // list of files in a package
rpm -qlp <package_file>
--last // Orders the package listing by install time(latest packages are at the top)
e.g.
rpm -qlp rsync-3.1.1-1.el5.rfx.i386.rpm
/etc/xinetd.d/rsync /usr/bin/rsync /usr/share/doc/rsync-3.1.1 /usr/share/doc/rsync-3.1.1/COPYING /usr/share/doc/rsync-3.1.1/INSTALL /usr/share/doc/rsync-3.1.1/NEWS ........................................
-c // displays a list of files marked as configuration files.
-d // files marked as documentation
-s // displays the state of all the files in the package.
Example
rpm -qf /usr/bin/ghostscript // To find out which package owns it
rpm -qip crontabs-1.10-32.1.el6.noarch.rpm // information about it
rpm -qa --qf "%{NAME}\n" // list package names only
查看 Package 的相互依賴:
rpm -q --whatrequires kernel
rpm -qR kernel // "-R" kernel "Requires" 什麼
Verify
rpm -Vf /usr/bin/tree
rpm -Va // 對整個系統測試
rpm -Vp tree-1.5.3-2.el6.x86_64.rpm // // 與某 package 對比
RPM-GPG-KEY
--checksig (-K)
rpm -K <rpm_file> // 檢查 digests and signatures
rpm -K --nosignature <rpm_file> // 單是測試檔案有沒有損壞
# 匯入 key
rpm --import /usr/share/rhn/RPM-GPG-KEY
# 查看安了什麼 pubkey
rpm -qa gpg-pubkey
gpg-pubkey-c105b9de-4e0fd3a3 gpg-pubkey-6b8d79e6-3f49313d gpg-pubkey-0608b895-4bd22942 gpg-pubkey-7fac5991-4615767f
# 查看 key 的內容
rpm -qi gpg-pubkey-c105b9de-4e0fd3a3
Name : gpg-pubkey Relocations: (not relocatable) Version : c105b9de Vendor: (none) Release : 4e0fd3a3 Build Date: Wed 08 Aug 2012 02:28:41 AM HKT Install Date: Wed 08 Aug 2012 02:28:41 AM HKT Build Host: localhost Group : Public Keys Source RPM: (none) Size : 0 License: pubkey Signature : (none) Summary : gpg(CentOS-6 Key (CentOS 6 Official Signing Key) <[email protected]>) Description : -----BEGIN PGP PUBLIC KEY BLOCK----- Version: rpm-4.8.0 (NSS-3) mQINBE4P06MBEACqn48FZgYkG2QrtUAVDV58H6LpDYEcTcv4CIFSkgs6dJ9TavCW ............................ -----END PGP PUBLIC KEY BLOCK-----
# remove the Red Hat GPG/DSA key
rpm -e gpg-pubkey-db42a60e
RPM Database Recovery
# to identify a stale lock
cd /var/lib/rpm
/usr/lib/rpm/rpmdb_stat -CA
OR
lsof | grep /var/lib/rpm
# 檢查完整性
/usr/lib/rpm/rpmdb_verify Packages
# 救它
mv Packages Packages.orig
/usr/lib/rpm/rpmdb_dump Packages.orig | /usr/lib/rpm/rpmdb_load Packages
# 測試:
rpm -qa 1> /dev/null
# rebuild the indexes
rpm -v --rebuilddb
設定 rpm db Path (--dbpath)
rpm -qa --dbpath /mnt/var/lib/rpm
"rpm -qa" without package version
在 rpm -qa | grep php56 時, result 是
... php56-php-fpm-5.6.40-11.el7.remi.x86_64 ...
如果只想出 package 名, 比如
php56-php-fpm
You can use rpm's --qf queryformat parameter (--queryformat)
rpm -qa --qf "%{NAME}\n"
To extract file from rpm file(rpm2cpio)
# Extract source files out of src.rpm file
# i: Restore archive
# d: Create leading directories where needed (current directory)
# m: Retain previous file modification times when creating files
# v: Verbose
cd /usr/src/package/code
rpm2cpio ../package.src.rpm | cpio -idmv
應用: 救回誤刪了的檔案
rpm -qf /usr/share/netdata/web/dashboard.js
netdata-data-1.45.4-1.el8.noarch
# download packages to the current directory
dnf download netdata-data
rpm -qlp netdata-data-1.45.5-1.el8.noarch.rpm | grep dashboard.js
rpm2cpio netdata-data-1.45.5-1.el8.noarch.rpm | cpio -idmv