$linuxjunkies
>

mock(1)

Build RPM packages in isolated chroot environments to ensure clean, reproducible builds without affecting the host system.

UbuntuDebianFedoraArch

Synopsis

mock [OPTION]... SPEC_FILE

Description

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

FlagWhat it does
-r CONFIGUse specified mock configuration (e.g., -r fedora-39-x86_64)
--rebuild SRPMRebuild an existing SRPM in the target environment
--cleanClean the chroot and remove all generated files
--initInitialize the chroot environment (create base filesystem)
--install PACKAGEInstall packages into the chroot without building
-v, --verboseIncrease verbosity of output
--enable-networkAllow network access during build (disabled by default for security)
--no-cleanup-afterLeave chroot intact after build for debugging
--define MACRO=VALUEDefine RPM macro for the build (e.g., --define dist=.fc39)
--arch ARCHITECTUREBuild for specified architecture (x86_64, aarch64, i386, etc.)
--shellOpen interactive shell in the chroot environment
--result DIRECTORYCopy 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.rpm

Build an RPM from a spec file for RHEL 9 target

mock -r rhel-9-x86_64 package.spec

Clean the chroot and reinitialize it with fresh base packages

mock -r fedora-39-x86_64 --clean --init

Build 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-devel

Build with custom RPM macro and verbose output

mock -r fedora-39-x86_64 package.spec --define 'dist=.fc39.test' -v

Build, leave chroot intact, and open shell for post-build inspection

mock -r fedora-39-x86_64 package.spec --no-cleanup-after --shell

List all available mock configuration targets on the system

mock --list-chroots

Related commands