I have a spec (myspecfile.spec) file that looks similar to

Name: package-%{myname}
Version: %{myversion}
Release: %{myrelease}
License: gpl2

Summary: this is my package
BuildArch: noarch

Some description of the package



I run rpmbuild like:

rpmbuild -bb new.spec --define 'myname my_name' --define 'myversion my_version' --define 'myrelease my_release' --define 'myprovide my_provide'

And /home/user/rpmbuild/RPMS/noarch/package-my_name-my_version-my_release.noarch.rpm is created.

All well and good, but is there any way to give one of my variables a default value? If I omit one of them?

Say, I run

rpmbuild -bb myfile.spec 

How can I get those variables listed to contain a default value?

If I do a %define myname my_name it will always contain this value no matter what I pass in via the command line.

2 Answers 2


You should be able to use a conditional

%if "%{?myname}" == ""
%define myname my_name

For example, using a very basic spec file:

% cat foo.spec 
%if "%{?foo}" == ""
%define foo  default

Name: package-%{foo}
Version: 1
Release: 1
License: gpl2
Summary: test
Source: foo


%setup -q


Now I can define foo or leave it at the default:

% rpmbuild -bs foo.spec             
Wrote: /home/sweh/rpmbuild/SRPMS/package-default-1-1.src.rpm

% rpmbuild -bs foo.spec -D 'foo bar'
Wrote: /home/sweh/rpmbuild/SRPMS/package-bar-1-1.src.rpm

See the documentation https://rpm-software-management.github.io/rpm/manual/macros.html

This will expand to content of variable my_name or to string default_name if variable my_name is not defined:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .