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.
rpm -i packagename-1.0.0-kll.i386.rpmInstall a package, verbose output
rpm -iv packagename-1.0.0-kll.i386.rpmInstall a package, verbose mode, print progress hash
rpm -ivh packagename-1.0.0-kll.i386.rpmUpgrade a package. Install package if not already installed.
rpm -Uvh packagename-1.0.0-kll.i386.rpmUpgrade a package if it is already installed. Does nothing if package is not installed.
rpm -Fvh packagename-1.0.0-kll.i386.rpmRe-Install an existing package (useful for corrupted packages)
rpm --replacepkgs -ivh packagename-1.0.0-kll.i386.rpmUninstall (erase) a package
rpm -e packagename rpm -e packagename-versionQuery if a package is installed
rpm -q packagenamePrint information about an installed package
rpm -qi packagenamePrint information about an rpm package file.
rpm -qip packagename-1.0.0-kll.i386.rpmPrint name of package that owns a file
rpm -qf /path/to/filePrint list of files belonging to a package
rpm -ql packagenamePrint names of all installed packages
rpm -qaPrint 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:
rpm --verify packagenameOr to verify all packages:
rpm -Va
| Maintenance |
Rebuild the RPM database
rpm --rebuilddb
| Building from Source |
Rebuild a source RPM (RPM 4.0)
rpmbuild --rebuild packagename-1.0.0-kll.src.rpmRebuild a source RPM (RPM 3.x)
rpm --rebuild packagename-1.0.0-kll.src.rpmRebuild a package with Athlon optimizations
rpmbuild --rebuild --target=athlon packagename-1.0.0-kll.src.rpmInstall RPM sources into ${RPMDIR}
rpm -i packagename-1.0.0-kll.src.rpmRebuild all packages, including source and binary RPMS, from a spec file
rpmbuild -ba packagename.specRebuild 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} |
/usr/lib/rpm/macros on most systems.
| %description |
| This program prints a friendly greeting. |
| %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 |
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. |
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.specOr, on RPM 4.0 systems:
rpmbuild -ba hello.specThis 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 --initdbInstall 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.rpmExtract 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/rpmNeed 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 dependenciesCheck relevant RPM sources to satisfy needed packages.