How to rebuild Ubuntu package from the sources

There are two ways (at least) to rebuild Ubuntu package from the source.
Using Ubuntu diff file and dpkg-buildpackage

  • Download source from Ubuntu repository.
  • Download Ubuntu diff file and apply it:
    patch -p1 < ubuntu.diff
  • Build package:
    dpkg-buildpackage -rfakeroot

Using .dsc file and debuild

  • Download .dsc file
  • Run following command:
    dpkg-source -x file.dsc
    Note, sometimes the archive with sources should be presented in the same directory!
  • Go to source directory and start building:

In both cases the development packages should be installed first:
sudo apt-get install build-essential devscripts