From Fedora Project Wiki

Revision as of 20:27, 19 June 2008 by Dwheeler (talk | contribs) (Put real content for the "building" section)

Creating Package HOWTO

This page describes the mechanics of how to create an RPM package for Fedora, and in particular, how to create a .spec file. It also gives some practical warnings about stuff that will or won't work, which may save you hours of time later.

Nearly all Linux distributions can install and uninstall programs as "packages". Fedora, and many other Linux distributions, use the "RPM" format for packages. There are tools that make it easy to create RPM packages; the key is to write a ".spec" file that explains to RPM how to build and install the program.

Setting up

Before you create RPM packages on Fedora, you need to install some core development tools and set up the account(s) you will use. As root:

 # yum groupinstall "Development Tools"
 # yum install rpmdevtools

It's strongly recommended that you create a new "dummy user" specifically for creating rpm packages. That way, if something goes terribly wrong, the program or build process can't trash your files, or send your private files/keys to the world. At the very least, you should normally not create your packages as user root. You can create a new user named "makerpm" quickly by doing:

 # /usr/sbin/useradd makerpm

Then log in as that special dummy user (makerpm).

Once you're logged in as the user who is creating packages, you then can then create the directory structure in your home directory by executing:

 $ rpmdev-setuptree

The "rpmdev-setuptree" program will create an "rpmbuild" directory in your $HOME directory. Underneath "rpmbuild" are a set of subdirectories (such as SPECS and BUILD), which you will use for creating your packages.

One you've set up your system and user account, you won't normally need to do these again.

Creating a spec file

Creating a RPMs from the spec file

Once you've create a spec file, say "program.spec", you can create source and binary RPMs by simply running this:

 $ rpmbuild -ba myprogram.spec

If this is successful, you'll find your binary RPM(s) in the "~/rpmbuild/RPMS/" subdirectory, and the source RPM in "~/rpmbuild/SRPMS".


For more information

This page only discusses the mechanics of creating a package. For more information about packaging, see Package Maintainers page, especially the Packaging Guidelines and How to join the Fedora Package Collection Maintainers (which explains how to become a package maintainer). The Updating Package HOWTO describes how to update an existing package you maintain in Fedora. Packaging/ScriptletSnippets Scriptlet Snippets has some useful examples of scriptlets.

For more information see: