James John – Software Engineer

Downloading Package Source Files and Rebuilding in Debian/Ubuntu

Gets to a point you might want to rebuild a package, maybe to be modified. It is easily done in Debian based systems.

We will be using nano for this post, we are going to download nano source and rebuild it to a .deb file. Before this is done, you have to add deb-src to your repository in order to be able to download source files of a package.

Editing Repositories

List of package repositories are written in /etc/apt/sources.list. Lets assume we only have this repository in there

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

With only that, we can’t download the source files of any package in that repository. What we have to do it add a deb-src repository of it, by adding:

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

Save the file and run $ sudo apt update to update files in the repository with our new one added

Downloading Source Files and Build Dependencies

Now we are done with editing the repository and made sure deb-src of the repository is present, we will now start downloading source files of nano by running:

$ sudo apt source nano

Screenshot_20160827_084340

After successfully downloaded the nano source files, we are now going to install the build dependencies (dependencies needed to build the package) by running:

$ sudo apt build-dep nano

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! 🙂

Re-Building Package

We have downloaded and modified the package to our taste (if you did any), now we are going to rebuild back to a .deb file. A package is needed to do this, you need to install devscripts if not installed in your system.

$ sudo apt install devscripts

After successful installation, we can now proceed to build the package. Before we proceed, we need to cd into our package source file directory; we downloaded nano so we have to go into the directory: cd nano* we can now run the build command:

$ sudo debuild -us -uc -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:

[...]
dpkg-deb: building package 'nano-dbgsym' in '../nano-dbgsym_2.6.3-1_amd64.deb'.
dpkg-deb: building package 'nano' in '../nano_2.6.3-1_amd64.deb'.
dpkg-deb: building package 'nano-tiny-dbgsym' in '../nano-tiny-dbgsym_2.6.3-1_amd64.deb'.
dpkg-deb: building package 'nano-tiny' in '../nano-tiny_2.6.3-1_amd64.deb'.
dpkg-deb: building package 'nano-udeb' in 'debian/.debhelper/scratch-space/build-nano-udeb/nano-udeb_2.6.3-1_amd64.deb'.
Renaming nano-udeb_2.6.3-1_amd64.deb to nano-udeb_2.6.3-1_amd64.udeb
dpkg-genchanges --build=any,all >../nano_2.6.3-1_amd64.changes
dpkg-genchanges: info: binary-only upload (no source code included)
dpkg-source --after-build nano-2.6.3
dpkg-buildpackage: info: binary-only upload (no source included)
Now running lintian...
warning: the authors of lintian do not recommend running it with root privileges!
Finished running lintian.

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

James John

Software Engineer