Linux Command rpm Command

Catalog

What is rpm?

The full name of rpm, The RPM Package Manager, is the package manager of the RHEL operating system with the suffix.Rpm.

RPM commands are used to install, uninstall, upgrade, query, list and check RPM packages on Linux systems.

install

rpm  -ivh  PACKAGE_FILE ...
  • -i, install package
  • -v, show command execution process
  • -h, output progress bar, show installation progress in number of #, one # indicates 2% progress

Example 1: Install the zsh package

[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%]

upgrade

rpm  -Uvh PACKAGE_FILE ...
rpm  -Fvh PACKAGE_FILE ...
  • -U, upgrade or install, upgrade if you have older packages installed, or install if no older packages exist.

  • -F: Upgrade, if there are old packages installed, upgrade, if there are no old packages, do not perform the upgrade operation.

Example 2: Upgrade the zsh package

[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%]

uninstall

rpm -e PACKAGE_NAME ...

Example 3: Uninstall the zsh package

[root@node1 ~]# rpm -e zsh

query

Example 4: Query all packages installed as RPM on the current system using rpm-qa

[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
...
  • -q, query
  • -a, query all installed packages

Example 5: Query specified packages using rpm-q

[root@node1 ~]# rpm -q zsh
zsh-5.0.2-34.el7.x86_64

Example 6: Use rpm-qf to query which package installed the specified file or directory

[root@node1 ~]# rpm -qf /bin/ls
coreutils-8.22-24.el7.x86_64
  • -f, --file, file name

Example 7: Use rpm-qi to query information about installed packages

[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.
  • -i, --info, information

Example 8: Use rpm-qc to query the configuration files installed on the current system for the specified package

[root@node1 ~]# rpm -qc zsh
/etc/skel/.zshrc
/etc/zlogin
/etc/zlogout
/etc/zprofile
/etc/zshenv
/etc/zshrc
  • -c, --configfiles, configuration file

Example 9: Use rpm-qd to query the documentation files installed on the current system for the specified package

[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
...
  • -d, --docfiles, document

Example 10: Query all directories installed on the current system for the specified package using 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
  • -l, --list, list

Example 11: Use rpm-qR to query the package on which the specified package depends

[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
  • -R, --requires, lists the functionality this package depends on

Example 12: Use rpm-q --scripts to query the scripts that come with the specified package

[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
...
  • --scripts, listing package-specific scripts used during installation and uninstallation.

check

Validating a package compares information about the installed files in the package with information about the files obtained from the package metadata stored in the rpm database.

rpm -V PACKAGE_FILE ...

Package Source Legality and Integrity Verification

  • Source validation: SHA256
  • Integrity verification: RSA

Package makers first use a one-way encryption algorithm to compute the package's signature, then use a private key to encrypt the signature and attach it to the end of the package. The producer's public key needs to be available to everyone, usually on the distribution disc.Software installers use public keys to verify the source legality and integrity of the software.

Obtain and import the public keys of trusted package producers:

For CentOS distribution

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7	

Verification:

(1) Verification will be performed automatically when programs signed by this organization are installed;

(2) Manual verification: rpm-K PACKAGE_FILE

Example: Take installing fping software from an epel source as an example, without importing the public key first.

[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%]

Example: To install the fping software in the epel source, import the public key and check it again.

[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%]

Example: How to view public keys that have been imported on the current system.

[root@node1 ~]# rpm -q gpg-pubkey
gpg-pubkey-352c64e5-52ae6884
gpg-pubkey-f4a80eb5-53a7ff4b

Database Maintenance

The database for the RPM package is located in the / var/lib/rpm directory.

  • --initdb initialization, if no database exists beforehand, create it, otherwise, do nothing.

  • --rebuilddb: Rebuild the database directly, whether it exists or not.

[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

Tags: Linux RPM CentOS shell Database

Posted on Mon, 18 May 2020 09:48:43 -0700 by loki1664