Package rebuilding is something easily done in Debian. As SysAdmin, you might find yourself in a spot needed to rebuild a Package, maybe to enable a feature or something.

This exactly I will show you how to do in this post. In this post, I will be using squid3 package. Before we proceed, I need to make sure my repository in /etc/apt/sources.list has deb-src repository part. With this, you can be able to download source files of package in a repository. Now in my repository, I have this

deb http://security.debian.org/ stable/updates main contrib non-free

This alone won’t get me the source files of squid3, I need to add the deb-src part, making it look like this

deb http://security.debian.org/ stable/updates main contrib non-free
deb-src http://security.debian.org/ stable/updates main contrib non-free

Saving this and run

$ apt update

Downloading Source Files and Rebuilding

I have added deb-src repository and updated my package list, now I can download source files of squid3

$ sudo apt source squid

screenshot_20160927_234240

After a successful download of source files, I’m going to downloading building dependencies – packages needed to build this package, by running

$ sudo apt build-dep squid3

This should install some packages if they are not installed in your system. After that, we can do any modifications we need to do to the package source files then ready to rebuild!

Modifying Package and Rebuilding

In this post, I will be enabling a http-violations in squid3 by cd into the package source folder which I just downloaded and edit the file debian/rules. Adding this option --enable-http-violations and save it

Building

Before building, I will make sure I have devscripts installed.

$ sudo apt install devscripts

With installation done, before building I have to cd back into the directory of the source package and then run

$ debuild -uc -us -b

Rebuilding of the package starts, enough debug will be returned to your console which you don’t need to worry about. But when building is done, you see something similar to this at the end:

[...]
dh_gencontrol -psquid  
dpkg-gencontrol: warning: package squid: unused substitution variable ${perl:Depends}
dh_md5sums -psquid 
dh_builddeb -psquid 
dpkg-deb: building package 'squid' in '../squid_3.5.19-1_amd64.deb'.
dh_gencontrol -psquid-dbg  
dh_md5sums -psquid-dbg 
dh_builddeb -psquid-dbg 
dpkg-deb: building package 'squid-dbg' in '../squid-dbg_3.5.19-1_amd64.deb'.
dh_gencontrol -psquidclient  
dh_md5sums -psquidclient 
dh_builddeb -psquidclient 
dpkg-deb: building package 'squidclient' in '../squidclient_3.5.19-1_amd64.deb'.
dh_gencontrol -psquid-cgi  
dh_md5sums -psquid-cgi 
dh_builddeb -psquid-cgi 
dpkg-deb: building package 'squid-cgi' in '../squid-cgi_3.5.19-1_amd64.deb'.
dh_gencontrol -psquid-purge  
dh_md5sums -psquid-purge 
dh_builddeb -psquid-purge 
dpkg-deb: building package 'squid-purge' in '../squid-purge_3.5.19-1_amd64.deb'.
 dpkg-genchanges --build=any,all >../squid3_3.5.19-1_amd64.changes
dpkg-genchanges: info: binary-only upload (no source code included)
 dpkg-source --after-build squid3-3.5.19
dpkg-buildpackage: info: binary-only upload (no source included)
Now running lintian...
N: 1 tag overridden (1 warning)
Finished running lintian.

Package has been successfully rebuilt and keep in the parent directory. You can now reinstall them using $ sudo dpkg -i squid3*.deb

Was this answer helpful? 262 Users Found This Useful (511 Votes)