RPM is the Red Hat package manager. It is a program designed to build and manage packages of software including the source and binaries. It is portable and can be run on different platforms.
RPMs (*.rpm) typically include the compiled programs and/or libraries needed for the package, documentation, install, verify, and uninstall scripts, and cryptographic signatures for each file in the package. This makes it easy to verify the integrity of the package. It also includes a list of packages that it depends on, and a list of services that are provided by the package.
RPM maintains a database of all installed packages in /var/lib/rpm/*. Included in the database is a list of all files installed by RPM and which package they belong to. This makes it a very powerful tool for finding out more about each package.
Sources are often provided in source RPMs (*.src.rpm or *.spm). These sources include the pristine developer source code, any patches applied by the package builder, and a SPEC file that is used to tell rpm how to compile the package.
You have to logged in as user root to install, upgrade, or remove packages. You can run queries as any user.
The RPM package format has been adopted by many major distributions besides Red Hat, including SuSE, Caldera, and TurboLinux.
These commands query a package that has already been installed. To query a package that has NOT been installed yet, add the -p option to the command.
For example, rpm -ql package would become | rpm -qpl package. |
To find out the package names using wildcards | rpm -qa | grep pattern |
What files are included in the the package | rpm -ql package |
To show general info on a package | rpm -qi package |
What package owns this file? | rpm -qf path/to/file |
What are the config files in a package? | rpm -qc package |
What are the documentation files in a package? | rpm -qd package |
What are the scripts in a package? | rpm -q --scripts package |
What services does this package provide? | rpm -q --provides package |
What services does this package require? | rpm -q --requires package |
To build/install an rpm source package
This installs the source in /usr/src/packages/SOURCES and installs the spec file in /usr/src/packages/SPECS.
RedHat systems use /usr/src/redhat/SOURCES and /usr/src/redhat/SPECS. Make a note of this if you are trying to use a package prepared for RedHat
This compiles the source and builds a binary rpm, then places it in /usr/src/packages/RPMS/Architecture.
Building a package from an rpm source package starts with the pristine sources from the developer, applies any patches from the package builder, and uses options in the SPEC file to compile and create the binary package.
This installs the binary package.
To extract the sources and apply patches from a source package (without building an rpm)
This installs the source in /usr/src/packages/SOURCES and installs the spec file in /usr/src/packages/SPECS.
This extracts the sources into /usr/src/packages/BUILD and applies any patches from the source package, but does not compile it or create a binary rpm package.
To bypass running the scripts in a package, use the --no-scripts option. There are 5 possible scripts in an rpm package:
pre-install
post-install
verify
pre-uninstall
post-uninstall
If you suspect the RPM database has been corrupted, run rpm --rebuilddb to rebuild it and try to recover from any errors.
To extract an individual file from an rpm package without installing the rpm:
1. Use rpm2cpio or rpm -qpl to list files and full paths in the package: rpm2cpio package | cpio -t
You need the full path name of a file to extract it in step 2.
2. Use rpm2cpio to extract a file. Run this command from your home directory or /tmp in order to avoid overwriting any current system files.
rpm2cpio package | cpio -iv --make-directories full-path
This creates the full path in the current directory and extracts the file you specified.
3. If you just want to convert it to a cpio archive, use
rpm2cpio package > cpio-archive-file
If you want to remove a list of RPMs without typing each on separately, you can use the xargs command with rpm. Here are the commands and output from a session where I wanted to delete several RPMs at once. First, I used rpm -qa to find all the xine RPMs. When I verified the list, I passed the list to xargs to execute an rpm -e on each of them. The final rpm -qa verifies that they have all been uninstalled.
artifact:~/datacore/suse-7.3/xine # rpm -qa | grep xine xine-lib-0.9.7-0 xine-lib-aa-0.9.7-0 xine-lib-alsa05-0.9.7-0 xine-lib-arts-0.9.7-0 xine-lib-d4d-0.9.7-0 xine-lib-docs-0.9.7-0 xine-lib-oggvorbis-0.9.7-0 xine-lib-oss-0.9.7-0 xine-lib-w32dll-0.9.7-0 xine-ui-0.9.7-0 xine-ui-aa-0.9.7-0 artifact:~/datacore/suse-7.3/xine # rpm -qa | grep xine | xargs rpm -e artifact:~/datacore/suse-7.3/xine # rpm -qa | grep xine artifact:~/datacore/suse-7.3/xine #