3.6. RPM macros

An rpm macro is a straight text substitution that can be conditionally assigned based on the optional evaluation of a statement when certain built-in functionality is used. Hence, RPM can perform text substitutions for you.

An example use is referencing the packaged software Version multiple times in a SPEC file. You define Version only once in the %{version} macro, and use this macro throughout the SPEC file. Every occurrence will be automatically substituted by Version that you defined previously.


If you see an unfamiliar macro, you can evaluate it with the following command:

$ rpm --eval %{_MACRO}

Evaluating the %{_bindir} and the %{_libexecdir} macros

$ rpm --eval %{_bindir}

$ rpm --eval %{_libexecdir}

One of the commonly-used macros is the %{?dist} macro, which signals which distribution is used for the build (distribution tag).

# On a RHEL 9.x machine
$ rpm --eval %{?dist}