Product SiteDocumentation Site

2.3. Building a Package

This section shows how to build your RPM package with the rpmbuild command.

Run rpmbuild as a non-root user

It is highly recommended to always run the rpmbuild command as a non-root, normal, user. If you build a package as the root user, possible mistakes in the spec file, for example in the %install section, can cause damage to your system.

2.3.1. Building an Example Package: eject

These steps show an example of building a package with a previously created spec file of the eject utility. For installation, eject only requires a minimum set of package dependencies. This makes it a good project to examine for package building.
Before starting with the package building process itself, make sure that you have created a non-root buildroot on your system.
Procedure 2.3. Building an example package: eject
  1. Download the source code archive for eject and place it in the ~/rpmbuild/SOURCES/ directory.
  2. Obtain the spec file for eject and place it in the ~/rpmbuild/SPECS/ directory.
  3. In a shell prompt, change to the ~/rpmbuild/SPECS/ directory and run the rpmbuild command:
     cd ~/rpmbuild/SPECS 
     rpmbuild -ba eject.spec 
  4. If you end up with an error message similar to the following one, it means that you have not installed the package dependencies required by the eject package:
    error: Failed build dependencies:
    libtool is needed by eject-2.1.5-0.1.x86_64
    1. You can use yum to install the needed files or packages. Run the following command to install the required libtool package:
       yum install -y libtool 
  5. In case you have received a build error related to the %install section, you may want to skip earlier stages of the build process with the --short-circuit option and restart the build process at the %install stage:
     rpmbuild -bi --short-circuit eject.spec 
  6. Once you get a clean build, the last line of the rpmbuild output will be as follows:
    + exit 0
  7. After a successful build with the rpmbuild -ba eject.spec command, the binary package will be placed in a subdirectory of the ~/rpmbuild/RPMS/ directory and the source package will be placed in ~/rpmbuild/SRPMS/.
  8. If you just want to create a source package (.src.rpm), run the following command:
     rpmbuild -bs eject.spec  
    This will create the source package in the ~/rpmbuild/SRPMS/ directory, or recreate it if it has been previously created.