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.