| RPMBUILD(1) | General Commands Manual | RPMBUILD(1) |
NAME¶
rpmbuild - Build RPM Package(s)
SYNOPSIS¶
rpmbuild -bSTAGE [options] SPEC_FILE ...
rpmbuild -rSTAGE [options] SOURCE_PACKAGE ...
rpmbuild -tSTAGE [options] TAR_ARCHIVE ...
rpmbuild {--rebuild|--recompile} [options] SOURCE_PACKAGE ...
DESCRIPTION¶
rpmbuild is used to build software packages in the RPM format, in an automated and repeatable manner.
An RPM package file (or package) consists of an archive of files and metadata used to install or erase the archived files. The metadata includes helper scripts, file attributes, and descriptive information about the package.
Packages come in two varieties: binary packages, used to encapsulate software to be installed, and source packages, containing the source code and recipe necessary to produce binary packages.
OPERATIONS¶
-bSTAGE
-rSTAGE
-tSTAGE
--rebuild, --recompile
STAGE is a single-letter argument that specifies the target stage to build. This also executes all preceding stages unless stated (or configured) otherwise. Additional steps beyond the one specified, such as clean up, may also execute. See BUILD PROCESS and OPTIONS for details.
Building packages¶
Use these STAGE arguments to produce RPM package files ready for installation and/or distribution.
a
b
r
s
Partial builds¶
Use these STAGE arguments to build or test the encapsulated software without producing RPM package files. Useful when packaging new software in RPM format and/or troubleshooting.
The corresponding spec sections are shown in parentheses where applicable.
p (%prep)
d (%generate_buildrequires)
f (%conf)
c (%build)
i (%install)
For historical reasons, this also includes the %check stage by default.
k (%check)
l
ARGUMENTS¶
SPEC_FILE
SOURCE_PACKAGE
TAR_ARCHIVE
OPTIONS¶
--build-in-place
--clean
--nobuild
--nocheck
--noclean
--nodebuginfo
--nodeps
--noprep
--rmsource
--rmspec
--rpmfcdebug
--scm=SCM
--short-circuit
--with OPTION
--without OPTION
See rpm-common(8) for the options common to all operations.
BUILD PROCESS¶
Packages are built in a number of logical steps, outlined below. The steps are executed from top to bottom, skipping any that aren't applicable to the spec.
Those steps that produce (intermediate) build artifacts or diagnostic output are called stages. They are denoted by a single-letter identifier in parentheses. You can tell rpmbuild to stop the build process at any stage (see OPERATIONS for details).
Some steps are implemented as build scriptlets whose contents is dumped in the rpmbuild output for diagnostic purposes. Their names are shown in parentheses following any stage identifier, prefixed with % if they correspond to a spec section or directive.
Binary packages are produced separately for one or more platforms, called build targets. By default, the current platform is the only build target. This can be overridden with --target or by declaring a BuildArch in the spec. See also BUGS for some related known issues.
- Unpack source package or tar archive if either is given
- Determine build targets and repeat following steps for each in turn
- Load rpm-config(5), rpm-rpmrc(5) and rpmbuild-config(5) files for next build target
- Parse spec file
- Check static build dependencies
- Setup build workspace
- Create build directory and set %builddir to its path (mkbuilddir)
- Export build environment to %builddir/rpmbuild.env file
- •
- Execute build scriptlets to populate %buildroot
- Unpack sources and apply any patches (p, %prep)
- Generate dynamic build dependencies (d, %generate_buildrequires)
- Check dynamic build dependencies
- Configure sources (f, %conf)
- Compile sources (c, %build)
- Install binaries into %buildroot (i, %install)
- Read dynamic spec parts
- Execute tests (k, %check)
- •
- Process files to be packaged
- Populate file list for source packages
- Populate file list for binary packages based on %files manifest(s)
- Add regular entries from %buildroot
- Copy special entries to %buildroot (%doc, %license)
- Add special entries from %buildroot
- Perform file classification
- Generate runtime dependencies using rpm-dependency-generators(7)
- Check file list against %buildroot (l)
- •
- Create packages
- Write binary packages to disk (b)
- Write source packages to disk (s)
- •
- Clean up
- OBSOLETE: Perform explicit clean up (%clean)
- Perform implicit clean up (rmbuild)
For more information on the syntax, see rpm-spec(5).
DYNAMIC BUILD DEPENDENCIES¶
When the %generate_buildrequires stage runs and some of the newly generated BuildRequires are not satisfied, rpmbuild creates an intermediate source package ending in buildreqs.nosrc.rpm, which has the new BuildRequires, and exits with code 11. This package can then be used in place of the original source package to resolve and install the missing build dependencies in the usual way, such as with dnf-builddep(8).
Multiple layers of dynamic build dependencies may exist in a spec file; the presence of specific BuildRequires on the system may yield new BuildRequires next time a build is performed with the same source package. The easiest way to ensure that all dynamic build dependencies are satisfied is to run the -br option, install the new dependencies of the buildreqs.nosrc.rpm package and repeat the whole procedure until rpmbuild no longer exits with code 11.
If the -br option is coupled with --nodeps, exit code 11 is always returned and a buildreqs.nosrc.rpm package is always created.
ENVIRONMENT¶
RPM_BUILD_NCPUS
EXIT STATUS¶
On success, 0 is returned, a nonzero failure code otherwise.
Packages with a %generate_buildrequires section will return with code 11 when there are unmet DYNAMIC BUILD DEPENDENCIES.
EXAMPLES¶
rpmbuild --rebuild hello-1.0-1.src.rpm
rpmbuild -bb --nocheck --with openssl hello.spec
rpmbuild -ta hello-2.0.tar.gz
rpmbuild -bc hello.spec
rpmbuild -bi --short-circuit hello.spec
FILES¶
See rpm-common(8)
BUGS¶
Building a spec that declares a BuildArch may cause unexpected behavior, in particular:
- •
- Macros defined before the BuildArch line will be expanded twice, which can yield unexpected results with %global in particular
- •
- Using a --target that disagrees with the BuildArch results in undefined behavior
SEE ALSO¶
gendiff(1), popt(3), rpm(8), rpm-common(8), rpmbuild-config(5), rpm2cpio(1), rpmkeys(8), rpmspec(1), rpmsign(1), rpm-setup-autosign(1) rpm-macros(7)
| 2026-08-20 | RPM 6.1.0 |