Basic guide to write Gentoo Ebuilds

This article Article description::contains instructions for beginners on ebuilds development.

Ebuilds, where do they live?
The location of ebuilds from the Gentoo repository (available in the snapshot) are usually at or in  for older installs. The location is determined by the repos.conf file. Custom ebuilds are recommended to be placed in a custom repository, say.

How to create an ebuild
Users of get the basic skeleton automatically (provided by ):

A similar tool is available for users of GNU Emacs or XEmacs (provided by or, respectively).

Users of other editors manually copy from the header.txt:

Essential information of the new package should be known and added to the ebuild-defined variables DESCRIPTION, HOMEPAGE, SRC_URI, LICENSE.

Example for a given source tarball
An ebuild for scrub, version 2.6.1 (if it didn't already exist) might read:

The SRC_URI is usually written with variables instead of hard coded.

Before testing we must create relationships between repositories

It can be tested using the command like:

This should download and unpack the source tarball. In some rare cases the package should work and no further adjustments is needed in the ebuild.

Patching
In case the source code needs to get patched the patch can be created from the unpacked source code as explained in the patches article.

The patch will then be listed in an array called  as is explained in the devmanual.

Adding support for user patches to ebuilds
Since EAPI 6, the support for user patches is provided by. This can be done by putting default on top in the src_prepare function:

EAPI versions prior to EAPI 7 should not be used for new ebuilds.

External resources

 * Quickstart Ebuild Guide
 * Gentoo Development guide
 * Common Ebuild Writing Mistakes
 * Michał Górny: The ultimate guide to EAPI 7
 * - The ebuild command's man page.
 * - The ebuild file format man page.
 * - To check for QA errors, QA keywords are explained in the last part of.
 * The skel.ebuild