Using the RPM Package Manager
Kwan Lowe
Updated: June 9, 2003
These are the notes I used during the RPM presentation. At some later time
I'll TeXify them, but don't hold your breath :D.
| Other Sources of Information |
Install a binary package
rpm -i packagename-1.0.0-kll.i386.rpm
Install a package, verbose output
rpm -iv packagename-1.0.0-kll.i386.rpm
Install a package, verbose mode, print progress hash
rpm -ivh packagename-1.0.0-kll.i386.rpm
Upgrade a package. Install package if not already installed.
rpm -Uvh packagename-1.0.0-kll.i386.rpm
Upgrade a package if it is already installed. Does nothing if
package is not installed.
rpm -Fvh packagename-1.0.0-kll.i386.rpm
Re-Install an existing package (useful for corrupted packages)
rpm --replacepkgs -ivh packagename-1.0.0-kll.i386.rpm
Uninstall (erase) a package
rpm -e packagename
rpm -e packagename-version
Query if a package is installed
rpm -q packagename
Print information about an installed package
rpm -qi packagename
Print information about an rpm package file.
rpm -qip packagename-1.0.0-kll.i386.rpm
Print name of package that owns a file
rpm -qf /path/to/file
Print list of files belonging to a package
rpm -ql packagename
Print names of all installed packages
rpm -qa
Print name and size of all installed packages
rpm -qa --queryformat "%-20{name} \t %20{size}\n"
Print name and summary for the package called bash.
rpm -q --queryformat "%{name} \t %{summary}\n" bash
Report if package contents, time stamps, checksums have changed.
Important flags include:
- S File Size
- M Permissions/Filetype
- 5 MD5 Sum
- U Ownership
- T Time stamp
Read the manpages for the full listing.
rpm --verify packagename
Or to verify all packages:
rpm -Va
Rebuild the RPM database
rpm --rebuilddb
Rebuild a source RPM (RPM 4.0)
rpmbuild --rebuild packagename-1.0.0-kll.src.rpm
Rebuild a source RPM (RPM 3.x)
rpm --rebuild packagename-1.0.0-kll.src.rpm
Rebuild a package with Athlon optimizations
rpmbuild --rebuild --target=athlon packagename-1.0.0-kll.src.rpm
Install RPM sources into ${RPMDIR}
rpm -i packagename-1.0.0-kll.src.rpm
Rebuild all packages, including source and binary RPMS, from a spec file
rpmbuild -ba packagename.spec
Rebuild a binary RPM from a spec file
rpmbuild -bb packagename.spec
Creating a local RPM build tree in $HOME
cd $HOME
mkdir -p rpm
cd rpm
mkdir BUILD RPMS SOURCES SPECS SRPMS
cd RPMS
mkdir i386 i486 i586 i686 athlon noarch ppc mipsel (etc...)
Edit ${HOME}/.rpmmacros
Add:
%_topdir ${HOME}/rpm
%_tmppath ${HOME}/tmp
# Change to 1 if you want to abort on unpackaged files
%_unpackaged_files_terminate_build 0
# Don't build debuginfo packages
%debug_package %{nil}
(NOTE: Use the full path instead of ${HOME} as $HOME is not expanded.
Why go through the hassle of creating an RPM to distribute your package?
The main reasons are ease of installation for the end user, the ability to
control exactly how your application gets installed, and the ability to
recreate the package exactly.
Download the sample
specfile and
source tarball for this next section.
Section 1
| Summary: A program to print a famous greeting. |
| Name: hello |
| Version: 1.0.0 |
| Release: 1 |
| Copyright: GPL |
| Group: System Environment/Base |
| Source: http://www.digitalhermit.com/~kwan/hello-1.0.0.tar.gz |
| BuildRoot: %{_tmppath}/%{name}-%{version} |
This section contains information about the package. The summary field is a
one line, er, summary of the entire package. The Name, Version and Release tags are
used to generate the final rpm package name. The basename of the Source
tag, in this case "hello-1.0.0.tar.gz", is the what RPM will attempt to extract
to build the package. BuildRoot specifies the temporary directory where the
package will get built. The environment variables are defined in
/usr/lib/rpm/macros on most systems.
| %description |
| This program prints a friendly greeting. |
The description tag contains a more in depth description of the package.
| %prep |
| %setup -q |
| |
| %build |
| make |
| |
| %install |
| make ROOT="$RPM_BUILD_ROOT" install |
| |
| %clean |
| rm -rf $RPM_BUILD_ROOT |
| |
| %files |
| %defattr(-,root,root) |
| %doc README |
| %{_bindir}/hello |
| |
These are the steps used to build and install the package. Note that the
ROOT variable is passed to the Makefile in our example package:
install: hello
install -m 755 -o 0 -g 0 -d $(ROOT)/usr/bin/
install -m 755 -o 0 -g 0 hello $(ROOT)/usr/bin/hello
Though not absolutely necessary, it allows the end-user to have more
control over where the package contents are installed.
RPM will automatically put files in the %doc tag in the proper documents
directory (often /usr/share/doc/). It also allows the option of not
installing the documentation files for small-disk systems.
| %changelog |
| * Mon Apr 7 2003 Kwan Lowe <kwan@digitalhermit.com> |
| - Did stuff. |
| |
| * Mon Apr 6 2003 Kwan Lowe <kwan@digitalhermit.com> |
| - Initial version. |
The changelog section details what changes have been made in this version
of the package. It allows the end-user to easily track the differences
between package versions.
To build the example package, place the hello-1.0.0.tar.gz file in your
${RPMROOT}/SOURCES directory and the hello.spec file in your
${RPMROOT}/SPECS directory. Next, change to the SPECS
directory and run the following command:
rpm -ba hello.spec
Or, on RPM 4.0 systems:
rpmbuild -ba hello.spec
This will create a source and binary RPM.
Create a new RPM database for the alternate root. The
${ROOTPATH}/var/lib/rpm
directory must exist. Note the difference between the install root specified
here and the build root in the previous section.
rpm --root=/path/to/alternate/root --initdb
Install package into an alternate root filesystem (useful for initial
installation of the Operating System. Also useful in case you break your system
and need to reinstall from a rescue disk (e.g., incorrect glibc library).
rpm --root=/path/to/alternate/root -ivh packagename-1.0.0-kll.i386.rpm
Extract files from a binary rpm.
mkdir tmp
cd tmp
rpm2cpio packagename-1.0.0-kll.i386.rpm | cpio -ivd
No job control in shell.
Verify that the system rpm macros file (/usr/lib/rpm/macros) contains
all the macros used in the package spec file.
error: cannot get exclusive lock on /var/lib/rpm/Packages
error: cannot open Packages index using db3 - Operation not permitted (1)
error: cannot open Packages database in /var/lib/rpm
Need to be root to install packages into system.
-or-
Another root session has locked the rpm database.
-or-
The database has not been created.
Failed dependencies
Check relevant RPM sources to satisfy needed packages.