RPM Cheat Sheet

Installation: rpm -ihv <package name>          rpmbuild -ba - build binary and source rpms
Upgrade: rpm -Uhv <package name>               rpmbuild -bb - build binary rpm
Freshen: rpm -Fhv <package names>              rpmbuild -bs - build source rpm
Erase: rpm -e <package name>                   rpmbuild --rebuild package.src.rpm - binary package 4m src

Query: rpm -q[option] <package name>                       RPM Divided into sections
        -qi = Query Package Information                    %description
        -ql = List Package Files                           %prep
        -qf = Query which package a file belongs           %build
to.                                                        %install
                                                           %files

.deb: Debian, Ubuntu and derived                   .rpm: RedHat, Fedora, SuSE, Mandriva
rpm -V[option] <package name> : Compare information about installed package files with information
stored in rpm database and note any discrepancies.
Example

%define name nano
%define version 2.0.9
%define release 1
Summary : Pico editor clone with enhancements
Name : %{name}
Version : %{version}
Release : %{release}
License : GPL
Group : Applications/Editors
URL : http://www.nano-editor.org/
Source : http://www.nano-editor.org/dist/v2.0/%{name}-%
{version}.tar.gz
BuildRoot : %{_tmppath}/%{name}-%{version}-root
BuildRequires : autoconf, automake, gettext-devel, ncursesdevel
%description
GNU nano is a small and friendly text editor. It aims to
emulate the Pico text editor while also offering a few
enhancements.
%prep
%setup -q
%build
%configure --enable-all
make
%install
rm -rf %{buildroot}
make DESTDIR="%{buildroot}" install
%files
%defattr(-,root,root)
%doc AUTHORS BUGS COPYING ChangeLog INSTALL NEWS README THANKS
Stage      Reads             Writes                                Action
%prep    %_sourcedir      %_builddir       This reads the sources and patches in the source
                                           directory %_sourcedir (usually ~/rpmbuild/SOURCES).
                                           It unpackages the sources to a subdirectory underneath
                                           the build directory %_builddir (usually
                                           ~/rpmbuild/BUILD/) and applies the patches.
%build   %_builddir       %_builddir       This compiles the files underneath the build
                                           directory %_builddir (usually ~/rpmbuild/BUILD/). This
                                           is often implemented by running some variation of
                                           "./configure ; make".
%check   %_builddir       %_builddir       Check that the software works properly. This is often
                                           implemented by running some variation of "make test".
                                           Many packages don't implement this stage.
%install %_builddir       %_buildrootdir   This reads the files underneath the build
                                           directory %_builddir (usually ~/rpmbuild/BUILD/) and
                                           writes to a directory underneath the build root
                                           directory %_buildrootdir (usually
                                           ~/rpmbuild/BUILDROOT). The files that are written are
                                           the files that are supposed to be installed when the binary
                                           package is installed by an end-user. Beware of the weird
                                           terminology: The build root directory is not the same as
                                           the build directory. This is often implemented by running
                                           "make install".
bin      %_buildrootdir   %_rpmdir         This reads the files underneath the build root
                                           directory %_buildrootdir (usually
                                           ~/rpmbuild/BUILDROOT/) to create binary RPM
                                           packages underneath the RPM directory %_rpmdir
                                           (usually ~/rpmbuild/RPMS/). Inside the RPM directory is
                                           a directory for each architecture, and a "noarch" directory
                                           for packages that apply to any architecture. These RPM
                                           files are the packages for users to install.
src      %_sourcedir      %_srcrpmdir      This creates a source RPM package (.src.rpm) inside the
                                           source RPM directory %_srcrpmdir (usually
                                           ~/rpmbuild/SRPMS). These files are needed for
                                           reviewing and updating packages.
Macro Name          Name                 Usually                        Purpose
%_specdir      Specification     ~/rpmbuild/SPECS             RPM specifications (.spec) files
               directory
%_sourcedir    Source            ~/rpmbuild/SOURCES   Pristine source package (e.g.,
               directory                              tarballs) and patches
%_builddir     Build directory   ~/rpmbuild/BUILD     Source files are unpacked and
                                                      compiled in a subdirectory
                                                      underneath this.
%_buildrootdir Build root        ~/rpmbuild/BUILDROOT Files are installed under here
               directory                              during the %install stage.
%_rpmdir       Binary RPM        ~/rpmbuild/RPMS      Binary RPMs are created stored
               directory                              under here.
%_srcrpmdir    Source RPM        ~/rpmbuild/SRPMS     Source RPMs are created and
               directory                              stored here.

Rpm cheatbook

  • 1.
    RPM Cheat Sheet Installation:rpm -ihv <package name> rpmbuild -ba - build binary and source rpms Upgrade: rpm -Uhv <package name> rpmbuild -bb - build binary rpm Freshen: rpm -Fhv <package names> rpmbuild -bs - build source rpm Erase: rpm -e <package name> rpmbuild --rebuild package.src.rpm - binary package 4m src Query: rpm -q[option] <package name> RPM Divided into sections -qi = Query Package Information %description -ql = List Package Files %prep -qf = Query which package a file belongs %build to. %install %files .deb: Debian, Ubuntu and derived .rpm: RedHat, Fedora, SuSE, Mandriva rpm -V[option] <package name> : Compare information about installed package files with information stored in rpm database and note any discrepancies. Example %define name nano %define version 2.0.9 %define release 1 Summary : Pico editor clone with enhancements Name : %{name} Version : %{version} Release : %{release} License : GPL Group : Applications/Editors URL : http://www.nano-editor.org/ Source : http://www.nano-editor.org/dist/v2.0/%{name}-% {version}.tar.gz BuildRoot : %{_tmppath}/%{name}-%{version}-root BuildRequires : autoconf, automake, gettext-devel, ncursesdevel %description GNU nano is a small and friendly text editor. It aims to emulate the Pico text editor while also offering a few enhancements. %prep %setup -q %build %configure --enable-all make %install rm -rf %{buildroot} make DESTDIR="%{buildroot}" install %files %defattr(-,root,root) %doc AUTHORS BUGS COPYING ChangeLog INSTALL NEWS README THANKS
  • 2.
    Stage Reads Writes Action %prep %_sourcedir %_builddir This reads the sources and patches in the source directory %_sourcedir (usually ~/rpmbuild/SOURCES). It unpackages the sources to a subdirectory underneath the build directory %_builddir (usually ~/rpmbuild/BUILD/) and applies the patches. %build %_builddir %_builddir This compiles the files underneath the build directory %_builddir (usually ~/rpmbuild/BUILD/). This is often implemented by running some variation of "./configure ; make". %check %_builddir %_builddir Check that the software works properly. This is often implemented by running some variation of "make test". Many packages don't implement this stage. %install %_builddir %_buildrootdir This reads the files underneath the build directory %_builddir (usually ~/rpmbuild/BUILD/) and writes to a directory underneath the build root directory %_buildrootdir (usually ~/rpmbuild/BUILDROOT). The files that are written are the files that are supposed to be installed when the binary package is installed by an end-user. Beware of the weird terminology: The build root directory is not the same as the build directory. This is often implemented by running "make install". bin %_buildrootdir %_rpmdir This reads the files underneath the build root directory %_buildrootdir (usually ~/rpmbuild/BUILDROOT/) to create binary RPM packages underneath the RPM directory %_rpmdir (usually ~/rpmbuild/RPMS/). Inside the RPM directory is a directory for each architecture, and a "noarch" directory for packages that apply to any architecture. These RPM files are the packages for users to install. src %_sourcedir %_srcrpmdir This creates a source RPM package (.src.rpm) inside the source RPM directory %_srcrpmdir (usually ~/rpmbuild/SRPMS). These files are needed for reviewing and updating packages. Macro Name Name Usually Purpose %_specdir Specification ~/rpmbuild/SPECS RPM specifications (.spec) files directory %_sourcedir Source ~/rpmbuild/SOURCES Pristine source package (e.g., directory tarballs) and patches %_builddir Build directory ~/rpmbuild/BUILD Source files are unpacked and compiled in a subdirectory underneath this. %_buildrootdir Build root ~/rpmbuild/BUILDROOT Files are installed under here directory during the %install stage. %_rpmdir Binary RPM ~/rpmbuild/RPMS Binary RPMs are created stored directory under here. %_srcrpmdir Source RPM ~/rpmbuild/SRPMS Source RPMs are created and directory stored here.