Modifying an existing Debian package: grep

This guide is a practical session on how to modify an existing debian package, when the version is not included in the current release. It is based on the excellent packaging tutorial and practical sessions of Lucas Nussbaum.

We are going to download a source deb package, build it without modifications, modify it, patch it, rebuild it and in the end, install it in our system.


  • A recent Debian or Ubuntu system.

Installation of development packages

$ sudo apt-get -y install build-essential debhelper devscripts packaging-dev debian-keyring

Get the source from the debian repos

$ dget

After that you should see these files under the current directory:

$ ls
grep_2.21-1.debian.tar.bz2  grep_2.21-1.dsc  grep_2.21.orig.tar.xz
  • grep_2.21-1.dsc: Package’s debian source control file.
  • grep_2.21.orig.tar.xz: Original source.
  • grep_2.21-1.debian.tar.bz2: Debian files and patches.

Unpack the source

The dpkg-source file will unpack the original and debian tarballs and apply the debian patches, if available.

$ dpkg-source -x grep_2.21-1.dsc

Download build dependencies

$ sudo apt-get -y build-dep grep

Build the unmodified package

Change into the source tree and run debuild. We are using the -us and -uc flags to suppress warnings about signing.

$ cd grep-2.21/
$ debuild -us -uc

It doesn’t take long before this package is build. In the parent directory you will find three more files:

  • grep_2.21-1_amd64.deb: the newly created deb package file.
  • the build log. You can use this to check for errors or warnings.
  • grep_2.21-1_amd64.changes: Debian applied changes.

Modify the package

I suggest you do not touch the source, unless you fancy spending your day debugging. We will simply make some modifications on the debian/changelog and debian/rules files.

  1. Add the --with-gnu-ld flag in the DEB_CONFIGURE_EXTRA_FLAGS line of the debian/rules file.

    The --with-gnu-ld is a trivial change and shouldn’t break anything during build. Find this line:

    DEB_CONFIGURE_EXTRA_FLAGS += --without-included-regex

    And change it to this:

    DEB_CONFIGURE_EXTRA_FLAGS += --without-included-regex --with-gnu-ld
  2. Update the changelog file.

    We are going to use the dch utility which is simply a wrapper around your default editor, with changelog syntax checking. Run the following command in the source tree:

    $ DEBFULLNAME="John Doe" DEBEMAIL="" dch -i

    Make the following changes (in bold) the debian/changelog file:

    grep (2.21-1ubuntu1) experimental; urgency=low
     * Support for GNU ld linker.
    -- John Doe <john>  Fri, 19 Jun 2015 13:01:37 +0300

    Note how the name and email of the patcher have been automatically inserted in the changelog entry. That’s because we defined the DEBFULLNAME and DEBEMAIL variables in the shell that runs dch.

Rebuild the modified package

$ debuild -us -uc

You will see the following error:

dpkg-source: error: aborting due to unexpected upstream changes, see /tmp/grep_2.21-1ubuntu1.diff.eYCcPk
dpkg-source: info: you can integrate the local changes with dpkg-source --commit
dpkg-buildpackage: error: dpkg-source -b grep-2.21 gave error exit status 2
debuild: fatal error at line 1376:

The above error happens because the --with-gnu-ld flag makes changes to the upstream source and this is against the Debian policy.

Apply patches for Policy compliance

$ cp /tmp/grep_2.21-1ubuntu1.diff.eYCcPk debian/patches/90-enable-gnu-ld.patch
$ echo 90-enable-gnu-ld.patch >> debian/patches/series

It is considered a good practice to edit the patch, add a description and a short summary and fill the headers related to the [Patch Tagging Guidelines]( "Patch Tagging Guidelines").

This method is only a workaround. The correct way to deal with patches is [Quilt]( "Quilt Howto").

Final rebuild of the modified package

$ debuild -us -uc

You will see five additional files in the parent directory:

  • grep_2.21-1ubuntu1_amd64.deb: the new deb package file.
  • grep_2.21-1ubuntu1.debian.tar.bz2: the new debian directory tarball.
  • grep_2.21-1ubuntu1.dsc: the new debian source control file.
  • the build log.
  • grep_2.21-1ubuntu1_amd64.changes: the changes file.

Checking the differences between original and new

The following commands will find the differences in the debian source control and changes files:

$ diff ../*.changes
$ diff ../*dsc

Install the new package

$ sudo debi

Check if grep is the correct version:

$ grep --version
grep (GNU grep) <strong>2.21</strong>
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <>.

All done. If you have reached so far congratulations! You have successfully rebuilt a Debian package.



By Theodotos Andreou

An old school Linux guy, a founding member of Ubuntucy and a founding member of Cyprus FOSS community. Currently working as sysadmin in the Cyprus University of Technology.

One reply on “Modifying an existing Debian package: grep”

Leave a Reply

Your email address will not be published. Required fields are marked *