In order to build a package from its sources, you need to enable the sources repositories in your distribution. In Linux Mint, with Synaptic installed, you can do it quite easily.
- Start Synaptic
- Authenticate yourself (for administration purposes)
- Menu –> Settings –> Repositories
- Enable source code repositories (see screenshot)
After enabling the source repositories, we will proceed from the console for convenience.
Getting started
If you have never compiled any source code before you will need a compiler and many other developer tools. Luckily there are a few packages in Debian based distributions that will install the essential tools with a single command.
$ sudo apt-get install build-essential devscripts
Getting the sources
Apt-get tool allows us to get sources directly from the repositories. This is quite practical if you want to get exactly the sources your distribution is using to build binary packages available in the repositories.
$ sudo apt-get source my_package
Patching the sources (optional)
There are many reasons why you want to build a package from the sources, but most probably you want to change some functionality. Now it is time to do it!
Building the package
Getting the dependencies
Software usually relies on libraries and other tools to accomplish a function. Debian source packages do not usually include those libraries unless the sources are statically linked against a specific version.
Before building our package, we need to get the development headers of the packages we depend on.
$ sudo apt-get build-dep my_package
Compiling the sources and building the package
To build the Debian package, move into the folder where your sources are located and type the following command. Be sure that your user has write permissions in the source folder and on-level up.
my_package-src $ dpkg-buildpackage -B -uc -us
This will build deb packages and will place them one-level up in your tree (therefore you need write permissions). Take a cup of coffee, it will take some time 🙂
Installing the package
$ sudo gdebi my_package_.deb
Locking the newly installed package
If you have patched the original sources, you would most probably avoid automatic updates to replace your package automatically with newer version. For this, you need to lock the package version. You can do it easily in Synaptic or from the command line
$ sudo apt-mark hold my_package