Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I am running an Ubuntu 12.04 LTS server. I currently have an issue where one of my used packages has an annoying bug. Instead of removing it and just building it from source, I want to integrate it into Ubuntus/Debians package management.

Coming from ArchLinux we did this by copying the original PKGBUILD and changing it in such a way that it compiles the new package. This is a very simple process but it informs the package manager about this package even though it is in no local repositories.

Is there a similar way for Ubuntu/Debian? Can I easily base my package on the outdated Ubuntu version and install this package instead of the original repository one?

Note: The concerning software is libvirt (I need 0.9.13 at least, 12.04 runs 0.9.8) and while I would appreciate a solution for this particular package in the comments, I am looking for a more general solution for such problems should they arise in the future.

Contrary to questions How can I manually assemble my own package “the hard way”? and What is the simplest Debian Packaging Guide? I am not interested in creating a new package but instead using existing resources and update them to a newer version.

share|improve this question
possible duplicate of How to get my software into Ubuntu? –  bodhi.zazen Jan 27 '14 at 22:13
This doesn't answer your question, but updated libvirt is in the Cloud Archive: –  Jorge Castro Jan 27 '14 at 22:14
You can always download the older package version from wherever, and then install it by hand, without repackaging everything. –  Thomas W. Jan 27 '14 at 22:45
@bodhi.zazen he wants to fix a bug locally no submitting a new package to Ubuntu. –  Braiam Jan 29 '14 at 1:47
@Braiam Thanks, I suppose I misunderstood "I want to integrate it into Ubuntus/Debians package management." –  bodhi.zazen Jan 29 '14 at 15:55

2 Answers 2

up vote 1 down vote accepted

I would download the source and the build dependencies for the Ubuntu version first:

apt-get install dpkg-dev
apt-get build-dep <package>
apt-get source <package>

The unmodified, upstream source the Ubuntu version is based on will be in a file called <pkg>_<ver>.orig.tar.gz (compression scheme may vary) - I would decompress this to one directory (let's call it "dir A"), then download the source to the bug-fixed version into another directory ("dir B"), and then generate a patch for what's changed:

diff -Nur <dirA> <dirB> >/tmp/upgrade.patch

Then change to the directory where apt-get source decompressed the modified Ubuntu version, and apply the patch

patch -p1 </tmp/upgrade.patch

Assuming there weren't many changes between the two upstream versions, and they didn't conflict with any of the Ubuntu packager's changes, this should work. Then edit debian/changelog in the Ubuntu package to give it a new version number, and dpkg-buildpackage should build you a custom version..

share|improve this answer

Just to toot my own horn, I have creating a solution for this exact circumstance. You can have a debian archive downloaded, unpacked, built, and reinstalled with 3 simple commands.

It is a shell script called debtool and is available on GitHub via the aforementioned link. As mentioned on the GitHub page, the script requires apt, dpkg, and fakeroot. It also requires dpkg-repack if you want to manipulate packages that are currently installed and no longer available via sources.

Building debian packages from source can be cumbersome, especially on a daily driver that you don't necessarily want to muddle up with numerous build dependencies and the like.

Assuming libvirt is available via sources, run the following command:

debtool --combo libvirt

The above command just downloaded the libvirt_0.9.8_all.deb file and unpacked it into the directory libvirt_0.9.8_all.

At this point you should make all of your changes to the files in the directory. You will also likely want to bump up the package's version number (i.e. 0.9.8-custom1) located in ./libvirt_0.9.8_all/DEBIAN/control.

Now build the new debian archive by running the following command:

debtool --build ./libvirt_0.9.8_all

Your finished debian archive is now in the current directory as libvirt_0.9.8-custom1_all.deb.

You can quickly reinstall this debian archive by running debtool --reinst ./libvirt_0.9.8-custom1_all.deb.


You can do a couple of other related things with debtool as well.

Show Available Versions

If there are several versions of a package available in the repositories, you can list them as follows:

debtool --show zsh

The above command will return the following:

zsh 5.0.5-4ubuntu1~ubuntu14.04.1 amd64
zsh 5.0.2-3ubuntu6 amd64

If you'd like to download the packages manually then you can use the --show-format option.

debtool --show --show-format zsh

Will return the following:

apt-get download zsh=5.0.5-4ubuntu1~ubuntu14.04.1 -a=amd64
apt-get download zsh=5.0.2-3ubuntu6 -a=amd64

Download Debian Archives

You can download the most recent version of a package as follows:

debtool --download zsh

You can download a specific version as follows:

debtool --download zsh=5.0.2-3ubuntu6

Note: You'll need to download the package manually if you require an architecture-specific package.

Unpacking Archives

You can unpack a debian archive on your hard drive as follows:

debtool --unpack package.deb

You can also unpack a package that is currently installed on your system as follows. Note: requires dpkg-repack

debtool --unpack package

If you have made changes to any of the installed files, they will be incorporated as well. This is perfect if you want to work with a package that is no longer available from sources or if you want to incorporate pre-existing fixes into a 'patched' deb.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.