10.1 About RPM Packaging

10.1.1 About RPM Categories
10.1.2 Administering RPMs
10.1.3 Building an RPM

On Oracle Linux, the RPM package manager provides the infrastructure for installation, upgrade, and removal of packages. Typically, each package bundles an application along with all the necessary binaries and documentation associated with that application. For example, the Apache Web server comes with a number of configuration files, a large set of documentation files, and the Apache Web server itself. All of this fits into one RPM package. One of the main advantages of the RPM system is that each rpm file holds a complete package.

For example, consider the package file that contains the GNU Compiler Collection is named gcc-4.4.6-4.el6.x86_64.rpm, where the package version is 4.4.6, the build number is 4, and the supported architecture and operating system are x86-64 and Oracle Linux 6.

You can use the RPM manager to copy an rpm file to another Linux system and install it, display the complete contents of the package, or remove or update the package.

An RPM file usually contains four sections:

10.1.1 About RPM Categories

RPMs can contain either binary or source packages.

A binary RPM is compiled for a particular target architecture such as x86_64, or noarch if its contents do not depend on the architecture as is the case for documentation and scripts. An example of a binary RPM might contain the GCC compiler and tools compiled for an Intel x86-64 target. Separate packages are required for each hardware platform that a package supports.

A source RPM provides the source code for binary packages and allows you to create a binary RPM.

10.1.2 Administering RPMs

In Oracle Linux, you can use the yum utility to install or upgrade RPM packages. The main benefit of using yum is that it also installs or upgrades any package dependencies. yum downloads the packages from repositories such as those that are available on the Unbreakable Linux Network (ULN) or the Oracle public yum server, but you can also set up your own repositories for use by systems that do not have Internet access. This section describes how to use the rpm command to administer packages that are not available in a yum repository.

Note

You need to be root to install, upgrade or erase an RPM.

To install or upgrade a package using rpm, specify the -U option:

# rpm -U package.rpm

If you specify the --test option, rpm tests the installation or upgrade process, but it does not install the package:

# rpm -U --test package.rpm

To remove a package (erase in RPM terminology), use the -e option:

# rpm -e package

To list every RPM package installed on a system:

# rpm -qa

You can filter the output using grep and sort if you are searching for a particular package, for example:

# rpm -qa | grep gcc | sort
gcc-4.4.6-4.el6.x86_64
gcc-c++-4.4.6-4.el6.x86_64
gcc-gfortran-4.4.6-4.el6.x86_64
libgcc-4.4.6-4.el6.i686
libgcc-4.4.6-4.el6.x86_64

To verify that an individual package has been installed, specify the package name, which can be in short form:

# rpm -q package

For example:

# rpm -q gcc-c++
gcc-c++-4.4.6-4.el6.x86_64

To display information about a package, use the -i option:

# rpm -qi package

To list all the files in a package, use the -l option:

# rpm -ql package

For more information about using rpm, see the rpm(8) manual page.

10.1.3 Building an RPM

Note

You do not need to be root to build an RPM.

To build an RPM:

  1. Create a tarball of the source code files for the package, for example:

    $ tar zcvf mypkg-1.0.tar.gz mypkg-1.0
  2. Copy the tarball to the SOURCES directory under /root/rpmbuild.

    $ cp mypkg-1.0.tar.gz /root/rpmbuild/SOURCES

    If you configure SOURCES in a different directory, you can use the --root option to specify this directory to the rpmbuild command.

  3. Create a specification (spec) file, which contains information about your package such as its name, the version, the release number, which packages are also required, and the name of the tarball. The file should contain at least the following sections:

    %prep

    Contains the commands to prepare for the build.

    %build

    Contains the commands to build the software. Usually, only make is required as most of the required instructions appear in the makefile.

    %install

    Contains the commands to install the newly built application or library.

    %clean

    Contains the commands to clean up any files that the commands in the previous sections create.

    %files

    Lists the files that go into the binary RPM along with their file attributes.

    See the spec files under /root/rpmbuild/SPECS for examples of how to create a spec file for your package.

    You can use the find-requires and find-provides scripts in /usr/lib/rpm to determine Perl, Python, Tcl script, Java package, and other dependencies. find-requires determines the shared libraries that are required by the files specified on the standard input. find-provides determines the shared libraries that a package provides from the files specified on the standard input.

  4. To build both a source RPM and a binary RPM, specify the -ba option and the name of the specification file to the rpmbuild command:

    $ rpmbuild -ba spec_file

    To build only the binary RPM, specify the -bb option instead.

Having built the packages, you can publish them on a Web server for downloading.

For more information about creating RPM packages, see the rpmbuild(8) manual page and the RPM documentation at http://www.rpm.org/wiki/Docs.