Getting Started

The specfile is what will involve the most work when creating an rpm.  It contains information about the package and also the instructions for how the package is created and installed.  To begin, change your directory to the SPEC directory created in the rpm build tree, and then create a specfile template.  I use the template every time  I write an rpm, and sometimes you don’t have to add anything besides the package specific information, such as the package name, to the specfile.

[user@localhost ~]$ cd rpmbuild/SPECS
[user@localhost SPECS]$ rpmdev-newspec
Skeleton specfile (minimal) has been created to "newpackage.spec".

Rename the file ‘newpackage.spec’ to whatever you want.  The first few lines of the specfile should look like this:



BuildRoot: %{_tmppath}/%{name}%{version}%{release}-root-%(%{__id_u} -n)




Macros can be used to set a variable, and there are a few that are already set.  To see these macros look in /usr/lib/rpm/macros or /usr/share/doc/rpm-[version]/macros, where [version] is the version of rpm.  The value of the macro is returned by putting the name of the macro in curly braces: %{ }.  Don’t confuse macros with the section headers in the specfile because they are different.  Here are some of the macros you will come across in this section of the tutorial:

  • %{_libdir}         /usr/lib
  • %{_bindir}        /usr/bin/
  • %{_tmppath}   /var/tmp

If you spot a macro you’re not familiar with to save time searching through one of those files you can alternatively just type rpm –eval [macro] into the terminal.

[brad@localhost ~]$ rpm --eval %_usr

Name, Version, and Release:

Most of this should be fairly straight forward.  Start with naming the package.  Under release the macro %{?dist} is the distribution.  Since I am using Fedora 9 for me this is .fc9.  The name of your rpm will appear in this order ‘[name]-[version]-[release].i386.rpm.’  i386 is the arch-type which can be changed by adding BuildArch: [arch].  So if you want to build a noarch pakage just add the line BuildArch: noarch.

Summary and Description:

Lets discuss the summary and %description together since they are not too different.  The summary is a very short one line description of what the program does.  The %description should not be the same as your summary.  Make the description a bit longer, and also more descriptive, but keep in mind there is still a character limit for each sentence in the description.  If any one line is too long rpmlint will tell you later on your description is too long.  In addition, don’t put a period at the end of the description.  This goes for the summary as well.  I have no idea why you have to do this, but RPM does not like them.


The Group is used as a way to classify packages.  To see a full list of all the groups look in the file /usr/share/doc/rpm-[version]/GROUPS, where [version] is the version of rpm you are using.


The license is the license for the program and should be included with the package when you create the rpm.  If your program is protected with the GNU General Public License then your license would be GPL.


Under url put the url for the homepage for the package.


The source is the name of the source tar file in the SOURCES directory.


You shouldn’t have to play with the buildroot so your best bet is to just leave this option alone.  This is the location though where the package is built and installed from.

BuildRequires and Requires:

BuildRequires is where packages are listed which are required for the package to be built.  The requires field is for dependencies of the package being created.  When the package is being built rpmbuild should detect these requirements, but it may not.  If they are not detected rpmbuild will fail, and tell you a dependancy is missing, and then you list that dependancy here.

At this point an example would probably be useful.  Here is an example of spec file I made for a package called vpython.

Building the Source:

After the %description is the part of the specfile where the source is built.  The first step is the preparation of the source.  The section is called %prep, and the only thing run here by default is the %setup macro.  Next the package is built in the %build section by running configure and make.  Afterwards in the %install section the package is installed by running make-install.  Once the package is built the build-root needs to be ‘cleaned’ for any future builds, and this occurs in the %clean section.

There are additional sections as well, but they are not put into the specfile template (if you you generate it with the command rpmdev-newspec).

  • %pre        – This is where code is run before the install scripts run.
  • %preun    – The section where code is executed prior to uninstall
  • %post      – Section for code to be executed after installation
  • %postun  – Section for code to be executed after uninstallation


This section is very important because it tells make-install which files need to be installed to the computer.  The %deffattr macro sets the default permissions for the files.  Use %doc to mark any documentation files, and then all files to be installed come afterwards.  If you don’t know all these files or the list is really long don’t worry because you can just leave the information blank for now. When you go to build the rpm later on it will fail and give an error saying that built packages were not installed.  After the error will be the list of all the files that need to be declared in this section.

For an example of what the files section looks like look at this spec file.  Here is a short clip of it:

%doc docs/LICENSE
%doc docs/README

The Changelog:

The changelog should be updated each time you update your rpm. Basically just write what has been modified, but there is a specific format for doing this.  Here is an example:

*Sun Jul 13 2008 <> 1
--Initial Build.
--Added file.
--Fixed bin/vpd, src/

If you get the syntax wrong don’t worry because either an error will occur when building or will be given when using rpmlint.

Previous Home Next

5 Responses to “Getting Started”

  1. Hari Rajan Says:

    as of now It is great … not just great , it is awesome.
    Well defined :). thank you too much,

    let me go thorugh all the pages.

  2. matou Says:

    %pre – This is where code is run before the install scripts run.

    this section does not work for me .
    I got a spec file from “” . every thing is ok ,but the rpm package can not create the “zabbix” user .

    any reply is appreciated .Thank you .

  3. NginxのRPMをリビルドしてインストールする | Says:

    […] Rpmbuild Tutorial(specファイルの記載方法) […]

  4. Zanon Says:

    Could you be so kind and tell me when you use %install , when %__install for example and when cp …. and %__cp

  5. Leo G Says:

    ./configure: error: invalid option “–build=x86_64-redhat-linux-gnu”

    I got the above error what should I do ?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: