$linuxjunkies
>

rpmbuild(8)

Build RPM packages from source code and spec files.

UbuntuDebianFedoraArch

Synopsis

rpmbuild [OPTION]... STAGE [FILE]...

Description

rpmbuild is used to build RPM binary and source packages from source code. It reads a spec file describing the package and executes the necessary build steps: unpacking sources, applying patches, compiling, installing, and creating the final RPM archives.

The tool supports multiple build stages, from preparing sources (-bp) through creating binary (-bb) and source (-bs) packages. It requires a properly formatted .spec file that defines build dependencies, compilation steps, and package metadata.

Common options

FlagWhat it does
-baBuild both binary and source RPM packages
-bbBuild only the binary RPM package
-bsBuild only the source RPM package (SRPM)
-bpExecute only the prep stage (unpack and patch sources)
-bcExecute up through the compile stage
-biExecute up through the install stage
--define MACRO VALUEDefine a macro variable for use in the spec file
-D 'MACRO VALUE'Define a macro with whitespace in the value
--with FEATUREEnable a conditional feature (bcond_with)
--without FEATUREDisable a conditional feature (bcond_without)
-vVerbose output showing build progress
--cleanRemove build directory after successful build

Examples

Build both binary and source RPMs from mypackage.spec in the current directory

rpmbuild -ba mypackage.spec

Build only a binary RPM package from the httpd spec file

rpmbuild -bb ~/rpmbuild/SPECS/httpd.spec

Build a source RPM with a custom dist tag for EL8

rpmbuild -bs package.spec --define 'dist .el8'

Build with debug support enabled and test suite disabled

rpmbuild -bb package.spec --with debug --without tests

Prepare sources by unpacking and applying patches without compiling

rpmbuild -bp package.spec

Build with verbose output and capture entire log to a file

rpmbuild -v -ba package.spec 2>&1 | tee build.log

Build using a custom RPM workspace directory instead of ~/rpmbuild

rpmbuild -bb --define '_topdir /custom/rpm' package.spec

Rebuild a binary package from a source RPM (SRPM)

rpmbuild --rebuild package-1.0-1.src.rpm

Related commands