reosoftproductions.com
RODNEY AND ARLYN'S WEB SITE

RPM Package Manager

Linux RPM Package Manager

RPM Package Manager

RPM Package Manager, or RPM, is a package management system. The name RPM variously refers to the .rpm file format, files in this format, software packaged in such files, and the package manager itself. RPM was intended primarily for Linux distributions; the file format is the baseline package format of the Linux Standard Base.

An RPM package can contain an arbitrary set of files. The larger part of RPM files encountered are binary RPMs, or BRPMs, containing the compiled version of some software. There are also source RPMs, or SRPMs, files containing the source code used to produce a package. These have an appropriate tag in the file header that distinguishes them from normal BRPMs, causing them to be extracted to /usr/src on installation. SRPMs customarily carry the file extension .src.rpm (.spm on file systems limited to 3 extension characters, e.g. old DOS FAT).

Useful Links

Features

For a system administrator performing software installation and maintenance, the use of package management rather than manual building has advantages such as simplicity, consistency and the ability for these processes to be automated and non-interactive.

Features of RPM include:

Repositories

RPMs are often collected centrally in one or more repositories on the internet. A site often has its own RPM repositories which may either act as local mirrors of such internet repositories or be locally maintained collections of useful RPMs.

yum keeps the repositories in the /etc/ym.repos.d directory.

Repository Links

Front Ends

Several front-ends to RPM ease the process of obtaining and installing RPMs from repositories and help in resolving their dependencies. These include:

Local RPM Installation Database

Working behind the scenes of the package manager is the RPM database, stored in /var/lib/rpm. It uses Berkeley DB as its back-end. It consists of a single database, named Packages, containing all of the meta information of the installed RPMs. Multiple databases are created for indexing purposes, replicating data to speed up queries. The database is used to keep track of all files that are changed and created when a user, using RPM, installs a package, thus enabling the user, via RPM, to reverse the changes and remove the package later. If the database gets corrupted (which is possible if the RPM client is killed), the index databases can be recreated with the rpm --rebuilddb command.

Contents of RPM Database

[root@hdcentos rpm]# ls -la
total 95492
drwxr-xr-x.  2 root root     4096 May 10 15:30 .
drwxr-xr-x. 61 root root     4096 May 10 16:22 ..
-rw-r--r--.  1 root root  4562944 May  2 13:02 Basenames
-rw-r--r--.  1 root root    16384 May  1 11:58 Conflictname
-rw-r--r--   1 root root   311296 May 10 15:31 __db.001
-rw-r--r--   1 root root    90112 May 10 15:31 __db.002
-rw-r--r--   1 root root  1318912 May 10 15:31 __db.003
-rw-r--r--.  1 root root        0 Dec 18 16:10 .dbenv.lock
-rw-r--r--.  1 root root  1974272 May  2 13:02 Dirnames
-rw-r--r--.  1 root root    32768 May  2 13:02 Group
-rw-r--r--.  1 root root    24576 May  2 13:02 Installtid
-rw-r--r--.  1 root root    77824 May  2 13:02 Name
-rw-r--r--.  1 root root    32768 Apr 24 19:43 Obsoletename
-rw-r--r--.  1 root root 86401024 May  2 13:02 Packages
-rw-r--r--.  1 root root  2240512 May  2 13:02 Providename
-rw-r--r--.  1 root root   577536 May  2 13:02 Requirename
-rw-r--r--.  1 root root        0 Dec 18 16:10 .rpm.lock
-rw-r--r--.  1 root root   139264 May  2 13:02 Sha1header
-rw-r--r--.  1 root root    77824 May  2 13:02 Sigmd5
-rw-r--r--.  1 root root     8192 Apr 26 13:49 Triggername

Description

Whilst the RPM format is the same across different Linux distributions, the detailed conventions and guidelines may vary across them.

Package filename and label

An RPM is delivered in a single file, normally in the format:

--..rpm

such as:

libgnomeuimm-2.0-2.0.0-3.i386.rpm

where is libgnomeuimm-2.0.

Source code may also be distributed in RPM packages; the part is specified as src:

libgnomeuimm-2.0-2.0.0-3.src.rpm

RPMs with the noarch.rpm extension refer to packages which do not depend on a certain computer's architecture. These include graphics and text for another program to use, and programs written in interpreted programming languages such as Python programs and shell scripts.

The RPM contents also include a package label, which contains the following pieces of information:

The package label fields do not need to match the filename.

Library Packaging

Libraries are distributed in two separate packages for each version. One contains the precompiled code for use at run-time, while the second one contains the related development files such as headers, etc. Those packages have -devel appended to their name field. The system administrator should ensure that the versions of the binary and development packages match.

Format

The format is binary and consists of four sections:

SPEC file

The "Recipe" for creating an RPM package is a spec file. Spec files end in the .spec suffix and contain the package name, version, RPM revision number, steps to build, install, and clean a package, and a changelog. Multiple packages can be built from a single RPM spec file, if desired. RPM packages are created from RPM spec files using the rpmbuild tool.

Spec files are usually distributed within SRPM files, which contain the spec file packaged along with the source code.

SRPM

A typical RPM is pre-compiled software ready for direct installation. The corresponding source code can also be distributed. This is done in an SRPM, which also includes the SPEC file describing the software and how it is built. The SRPM also allows the user to compile, and perhaps modify, the code itself.

A software package may contain only scripts that are architecture-independent. In such a case only an SRPM may be available; this is still an installable RPM.

Commands

General

--help

[root@hdcentos ~]# rpm -?
Usage: rpm [OPTION...]

Query/Verify package selection options:
  -a, --all                        query/verify all packages
  -f, --file                       query/verify package(s) owning file
  -g, --group                      query/verify package(s) in group
  -p, --package                    query/verify a package file
  --pkgid                          query/verify package(s) with package
                                   identifier
  --hdrid                          query/verify package(s) with header
                                   identifier
  --triggeredby                    query the package(s) triggered by the
                                   package
  --whatrequires                   query/verify the package(s) which require a
                                   dependency
  --whatprovides                   query/verify the package(s) which provide a
                                   dependency
  --nomanifest                     do not process non-package files as
                                   manifests

Query options (with -q or --query):
  -c, --configfiles                list all configuration files
  -d, --docfiles                   list all documentation files
  -L, --licensefiles               list all license files
  --dump                           dump basic file information
  -l, --list                       list files in package
  --queryformat=QUERYFORMAT        use the following query format
  -s, --state                      display the states of the listed files

Verify options (with -V or --verify):
  --nofiledigest                   don't verify digest of files
  --nofiles                        don't verify files in package
  --nodeps                         don't verify package dependencies
  --noscript                       don't execute verify script(s)

Install/Upgrade/Erase options:
  --allfiles                       install all files, even configurations
                                   which might otherwise be skipped
  --allmatches                     remove all packages which match <package>
                                   (normally an error is generated if
                                   <package> specified multiple packages)
  --badreloc                       relocate files in non-relocatable package
  -e, --erase=<package>+           erase (uninstall) package
  --excludedocs                    do not install documentation
  --excludepath=<path>             skip files with leading component <path> 
  --force                          short hand for --replacepkgs --replacefiles
  -F, --freshen=<packagefile>+     upgrade package(s) if already installed
  -h, --hash                       print hash marks as package installs (good
                                   with -v)
  --ignorearch                     don't verify package architecture
  --ignoreos                       don't verify package operating system
  --ignoresize                     don't check disk space before installing
  -i, --install                    install package(s)
  --justdb                         update the database, but do not modify the
                                   filesystem
  --nodeps                         do not verify package dependencies
  --nofiledigest                   don't verify digest of files
  --nocontexts                     don't install file security contexts
  --noorder                        do not reorder package installation to
                                   satisfy dependencies
  --noscripts                      do not execute package scriptlet(s)
  --notriggers                     do not execute any scriptlet(s) triggered
                                   by this package
  --nocollections                  do not perform any collection actions
  --oldpackage                     upgrade to an old version of the package
                                   (--force on upgrades does this
                                   automatically)
  --percent                        print percentages as package installs
  --prefix=<dir>                   relocate the package to <dir>, if
                                   relocatable
  --relocate=<old>=<new>           relocate files from path <old> to <new>
  --replacefiles                   ignore file conflicts between packages
  --replacepkgs                    reinstall if the package is already present
  --test                           don't install, but tell if it would work or
                                   not
  -U, --upgrade=<packagefile>+     upgrade package(s)

Common options for all rpm modes and executables:
  -D, --define='MACRO EXPR'        define MACRO with value EXPR
  --undefine=MACRO                 undefine MACRO
  -E, --eval='EXPR'                print macro expansion of EXPR
  --macros=<FILE:...>              read <FILE:...> instead of default file(s)
  --nodigest                       don't verify package digest(s)
  --nosignature                    don't verify package signature(s)
  --rcfile=<FILE:...>              read <FILE:...> instead of default file(s)
  -r, --root=ROOT                  use ROOT as top level directory (default:
                                   "/")
  --dbpath=DIRECTORY               use database in DIRECTORY
  --querytags                      display known query tags
  --showrc                         display final rpmrc and macro configuration
  --quiet                          provide less detailed output
  -v, --verbose                    provide more detailed output
  --version                        print the version of rpm being used

Options implemented via popt alias/exec:
  --scripts                        list install/erase scriptlets from
                                   package(s)
  --setperms                       set permissions of files in a package
  --setugids                       set user/group ownership of files in a
                                   package
  --conflicts                      list capabilities this package conflicts
                                   with
  --obsoletes                      list other packages removed by installing
                                   this package
  --provides                       list capabilities that this package provides
  --requires                       list capabilities required by package(s)
  --info                           list descriptive information from package(s)
  --changelog                      list change logs for this package
  --xml                            list metadata in xml
  --triggers                       list trigger scriptlets from package(s)
  --last                           list package(s) by install time, most
                                   recent first
  --dupes                          list duplicated packages
  --filesbypkg                     list all files from each package
  --fileclass                      list file names with classes
  --filecolor                      list file names with colors
  --fscontext                      list file names with security context from
                                   file system
  --fileprovide                    list file names with provides
  --filerequire                    list file names with requires
  --filecaps                       list file names with POSIX1.e capabilities

Help options:
  -?, --help                       Show this help message
  --usage                          Display brief usage message

--usage

[root@hdcentos ~]# rpm --usage
Usage: rpm [-aKfgpqVcdLilsiv?] [-a|--all] [-f|--file] [-g|--group]
        [-p|--package] [--pkgid] [--hdrid] [--triggeredby] [--whatrequires]
        [--whatprovides] [--nomanifest] [-c|--configfiles] [-d|--docfiles]
        [-L|--licensefiles] [--dump] [-l|--list] [--queryformat=QUERYFORMAT]
        [-s|--state] [--nofiledigest] [--nofiles] [--nodeps] [--noscript]
        [--allfiles] [--allmatches] [--badreloc] [-e|--erase <package>+]
        [--excludedocs] [--excludepath=<path>] [--force]
        [-F|--freshen <packagefile>+] [-h|--hash] [--ignorearch] [--ignoreos]
        [--ignoresize] [-i|--install] [--justdb] [--nodeps] [--nofiledigest]
        [--nocontexts] [--noorder] [--noscripts] [--notriggers]
        [--nocollections] [--oldpackage] [--percent] [--prefix=<dir>]
        [--relocate=<old>=<new>] [--replacefiles] [--replacepkgs] [--test]
        [-U|--upgrade <packagefile>+] [-D|--define 'MACRO EXPR']
        [--undefine=MACRO] [-E|--eval 'EXPR'] [--macros=<FILE:...>]
        [--nodigest] [--nosignature] [--rcfile=<FILE:...>] [-r|--root ROOT]
        [--dbpath=DIRECTORY] [--querytags] [--showrc] [--quiet]
        [-v|--verbose] [--version] [-?|--help] [--usage] [--scripts]
        [--setperms] [--setugids] [--conflicts] [--obsoletes] [--provides]
        [--requires] [--info] [--changelog] [--xml] [--triggers] [--last]
        [--dupes] [--filesbypkg] [--fileclass] [--filecolor] [--fscontext]
        [--fileprovide] [--filerequire] [--filecaps]

--version

[root@hdcentos ~]# rpm --version
RPM version 4.11.3

Packages

List all Installed Packages

Type the following command to print the all the names of installed packages on your Linux system. Sort the output by name.

[root@hdcentos rpm]# rpm -qa | sort
abattis-cantarell-fonts-0.0.16-3.el7.noarch
abrt-2.1.11-36.el7.centos.x86_64
abrt-addon-ccpp-2.1.11-36.el7.centos.x86_64
abrt-addon-kerneloops-2.1.11-36.el7.centos.x86_64
...

List all Installed Packages that start with 'rpm'

Type the following command to print the all the names of installed packages on your Linux system that start with the name 'rpm'. Sort the output by name.

[root@hdcentos rpm]# rpm -qa rpm* | sort
rpm-4.11.3-17.el7.x86_64
rpm-build-libs-4.11.3-17.el7.x86_64
rpmforge-release-0.5.3-1.el7.rf.x86_64
rpm-libs-4.11.3-17.el7.x86_64
rpm-python-4.11.3-17.el7.x86_64

Query Information for a Package

[root@hdcentos rpm]# rpm -qi rpm
Name        : rpm
Version     : 4.11.3
Release     : 17.el7
Architecture: x86_64
Install Date: Fri 18 Dec 2015 04:11:54 PM PST
Group       : System Environment/Base
Size        : 2621781
License     : GPLv2+
Signature   : RSA/SHA256, Wed 25 Nov 2015 07:36:43 AM PST, Key ID 24c6a8a7f4a80eb5
Source RPM  : rpm-4.11.3-17.el7.src.rpm
Build Date  : Fri 20 Nov 2015 03:15:20 AM PST
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem 
Vendor      : CentOS
URL         : http://www.rpm.org/
Summary     : The RPM package management system
Description :
The RPM Package Manager (RPM) is a powerful command line driven
package management system capable of installing, uninstalling,
verifying, querying, and updating software packages. Each software
package consists of an archive of files along with information about
the package like its version, a description, etc.

Update a Package

If we want to upgrade any RPM package -U upgrade option will be used. One of the major advantages of using this option is that it will not only upgrade the latest version of any package, but it will also maintain the backup of the older package so that in case if the newer upgraded package does not run the previously installed package can be used again.

rpm -Uvh rpm-4.11.3-17.el7.x86_64

Install a Package

RPM is capable of performing many tasks when it comes to package management. The one thing people think of first is the installation of software. Installing new software is a complex, error-prome job. With RPM, this job can be accomplished with a single command.

When installing software that's been packaged into an RPM package file, the following tasks can be accomplished by RPM.

The following is a typical install command using RPM:

rpm -ivh rpmfile