RPM command examples to query, install, remove and upgrade packages

All software on a Linux system is divided into packages that can be installed, uninstalled, upgraded, queried, and verified. CentOS/RHEL uses the Red Hat Package Manager (RPM) to facilitate the installation, upgrade and removal of software packages.

The rpm utility provides many useful options for querying and verifying packages, as well as installing, upgrading, and removing packages. The following provides examples of these options.

Query Packages

1. Listing all installed packages

To list all installed packages, use the following command:

# rpm -qa | more
NetworkManager-team-1.8.0-9.el7.x86_64
pyxattr-0.5.1-5.el7.x86_64
HPOvXpl-11.14.014-1.x86_64
bind-utils-9.9.4-51.el7.x86_64
pyOpenSSL-0.13.1-3.el7.x86_64
....

The format of rpm package names is name-version-release.architecture. The example shows packages for version 7 of EnterPrise Linux (el7) with architectures of either:

  • x86_64: Any AMD64 or Intel 64 CPUs
  • noarch: Any CPU architecture
  • i686: 32-bit OS

2. Display Package Information

To display detailed package information (of the bash package, for example), enter:

# rpm -ql bash
/etc/skel/.bash_logout
/etc/skel/.bash_profile
/etc/skel/.bashrc
/usr/bin/alias
/usr/bin/bash
/usr/bin/bashbug
/usr/bin/bashbug-64
/usr/bin/bg

3. Find the package from a file

To perform a reverse search, that is to determine what package a specific file (/etc/hosts, for example) belongs to, enter:

# rpm -qf /etc/hosts
setup-2.8.71-7.el7.noarch

4. Find configuration files of a package

To list configuration files associated with a package (the bash package, for example), enter:

# rpm -qc bash
/etc/skel/.bash_logout
/etc/skel/.bash_profile
/etc/skel/.bashrc

Installing and Updating Packages

1. Installing or Upgrading packages

Using the rpm -U package_name command upgrades installed packages, as well as installs
new packages. For example, to install or upgrade the rsync package:

# rpm –Uvh rsync-3.0.9-18.el7.x86_64.rpm
  • -v (verbose) option displays more information
  • -h (hash) option displays progress.

2. Installing a New Kernel

When installing a new kernel, use the –i option so as not to upgrade the current kernel, for example:

# rpm –ivh kernel-3.10.0-229.el7.x86_64.rpm

Removing Packages

To remove a package (the rsync package, for example), enter:

# rpm –e rsync
Related Post