mock(1)
Build RPM packages in isolated chroot environments to ensure clean, reproducible builds without affecting the host system.
Synopsis
mock [OPTION]... SPEC_FILEDescription
mock is a tool for building RPM packages in a clean chroot environment. It isolates the build process from the host system, preventing dependency pollution and ensuring builds are reproducible across different machines. mock downloads and installs only the necessary dependencies, then removes them after the build completes.
Commonly used by Fedora and Red Hat for package builds, mock supports multiple architectures and distribution targets. Configuration files define the chroot environment, compiler flags, and package repositories used during builds.
Common options
| Flag | What it does |
|---|---|
-r CONFIG | Use specified mock configuration (e.g., -r fedora-39-x86_64) |
--rebuild SRPM | Rebuild an existing SRPM in the target environment |
--clean | Clean the chroot and remove all generated files |
--init | Initialize the chroot environment (create base filesystem) |
--install PACKAGE | Install packages into the chroot without building |
-v, --verbose | Increase verbosity of output |
--enable-network | Allow network access during build (disabled by default for security) |
--no-cleanup-after | Leave chroot intact after build for debugging |
--define MACRO=VALUE | Define RPM macro for the build (e.g., --define dist=.fc39) |
--arch ARCHITECTURE | Build for specified architecture (x86_64, aarch64, i386, etc.) |
--shell | Open interactive shell in the chroot environment |
--result DIRECTORY | Copy built RPMs to specified directory after build completes |
Examples
Rebuild a source RPM for Fedora 39 in an isolated x86_64 chroot
mock -r fedora-39-x86_64 --rebuild package-1.0-1.src.rpmBuild an RPM from a spec file for RHEL 9 target
mock -r rhel-9-x86_64 package.specClean the chroot and reinitialize it with fresh base packages
mock -r fedora-39-x86_64 --clean --initBuild package and copy resulting RPMs to ./rpms/ directory
mock -r fedora-39-x86_64 package.spec --result ./rpms/Install development packages into chroot for dependency testing
mock -r fedora-39-x86_64 --install systemd-devel glib2-develBuild with custom RPM macro and verbose output
mock -r fedora-39-x86_64 package.spec --define 'dist=.fc39.test' -vBuild, leave chroot intact, and open shell for post-build inspection
mock -r fedora-39-x86_64 package.spec --no-cleanup-after --shellList all available mock configuration targets on the system
mock --list-chroots