Build RPMs

Build RPM packages for sample bello, pello, and cello programs by using the rpmbuild utility.

Different use cases require different combinations of arguments to the rpmbuild command. The following are the main use cases:

  • Building source RPMs.
  • Building binary RPMs:
    • Rebuilding a binary RPM from a source RPM.
    • Building a binary RPM from the spec file.
Note
When using the rpmbuild command, a certain directory and file structure is expected, which is the same as the structure that was configured by the rpmdev-setuptree utility.

Build a source RPM

Put a source code of the bello, pello, and cello sample programs into Source RPM (SRPM) packages by using the rpmbuild utility.

Before you begin

About this task

Building Source RPMs (SRPMs) has the following advantages:

  • You can preserve the exact source of a certain Name-Version-Release (NVR) of an RPM file that was deployed to an environment. This includes the exact spec file, the source code, and all relevant patches. This is useful for tracking and debugging purposes.
  • You can build a binary RPM on a different hardware platform or architecture.

Procedure

  1. Navigate to the ~/rpmbuild/SPECS/ directive, which contains the created spec file:
    $ cd ~/rpmbuild/SPECS/
  2. Build the source RPM by entering the rpmbuild command with the specified spec file:
    $ rpmbuild -bs <specfile>

    The -bs option stands for the build source.

    For example, to build source RPMs for the bello, pello, and cello programs, complete the following steps:

    1. Build a source RPM for the bello program:
      $ rpmbuild -bs bello.spec
      Wrote: /home/admiller/rpmbuild/SRPMS/bello-0.1-1.el8.src.rpm
    2. Build a source RPM for the pello program:
      $ rpmbuild -bs pello.spec
      Wrote: /home/admiller/rpmbuild/SRPMS/pello-0.1.2-1.el8.src.rpm
    3. Build a source RPM for the cello program:
      $ rpmbuild -bs cello.spec
      Wrote: /home/admiller/rpmbuild/SRPMS/cello-1.0-1.el8.src.rpm

Results

  • Verify that the rpmbuild/SRPMS directory includes the resulting source RPMs. The directory is a part of the structure expected by rpmbuild.

Rebuild a binary RPM from a source RPM

Rebuild binary RPM packages for sample bello, pello, and cello programs from their source RPM (SRPM) packages by using the rpmbuild utility. You can then install and run the binary packages on multiple systems.

Before you begin

  • You installed the rpmbuild utility on your system:
    # dnf install rpm-build

About this task

The output generated when creating the binary RPM is verbose, which is helpful for debugging. The output varies for different examples and corresponds to their spec files.

The resulting binary RPMs are located in either of the following directories:

  • ~/rpmbuild/RPMS/YOURARCH, where YOURARCH is your architecture
  • ~/rpmbuild/RPMS/noarch/, if the package is not architecture-specific

Procedure

  1. Navigate to the ~/rpmbuild/SRPMS/ directive, which contains the SRPM:
    $ cd ~/rpmbuild/SRPMS/
  2. Rebuild the binary RPM from the SRPM:
    $ rpmbuild --rebuild <srpm>

    For example, to rebuild bello, pello, and cello from their SRPMs, complete the following steps:

    1. Rebuild the bello program:
      $ rpmbuild --rebuild bello-0.1-1.el8.src.rpm
    2. Rebuild the pello program:
      $ rpmbuild --rebuild pello-0.1.2-1.el8.src.rpm
    3. Rebuild the cello program:
      $ rpmbuild --rebuild cello-1.0-1.el8.src.rpm
    Note

    Invoking rpmbuild --rebuild involves the following processes:

    • Installing the contents of the SRPM (the spec file and the source code) into the ~/rpmbuild/ directory.
    • Building an RPM by using the installed contents.
    • Removing the spec file and the source code.

    You can retain the spec file and the source code after building either of the following ways:

    • When building the RPM, use the rpmbuild command with the --recompile option instead of the --rebuild option.
    • Install SRPMs for the bello, pello, and cello programs:
      1. Install the SRPM for bello:
        $ rpm -Uvh ~/rpmbuild/SRPMS/bello-0.1-1.el8.src.rpm
        Updating / installing...
           1:bello-0.1-1.el8               [100%]
      2. Install the SRPM for pello:
        $ rpm -Uvh ~/rpmbuild/SRPMS/pello-0.1.2-1.el8.src.rpm
        Updating / installing...
        ...1:pello-0.1.2-1.el8              [100%]
      3. Install the SRPM for cello:
        $ rpm -Uvh ~/rpmbuild/SRPMS/cello-1.0-1.el8.src.rpm
        Updating / installing...
        ...1:cello-1.0-1.el8            [100%]

Build a binary RPM from a spec file

Build binary RPMs for sample bello, pello, and cello programs from their spec files by using the rpmbuild command.

Before you begin

  • You have installed the rpmbuild utility on your system:
    # dnf install rpm-build

Procedure

  1. Navigate to the ~/rpmbuild/SPECS/ directive, which contains spec files:
    $ cd ~/rpmbuild/SPECS/
  2. Build the binary RPM from its spec:
    $ rpmbuild -bb <spec_file>

    For example, to build bello, pello, and cello binary RPMs from their spec files, complete the following steps:

    1. Build the bello program:
      $ rpmbuild -bb bello.spec
    2. Build the pello program:
      $ rpmbuild -bb pello.spec
    3. Build the cello program:
      $ rpmbuild -bb cello.spec