If you are using a major Linux distro like Ubuntu or Fedora, it would have come with a package manager that allows you to easily install binary packages (DEB or RPM) in your system. However, if you are planning to customize the software you are installing, like adding additional features, then you might want to use the source packages and compile them yourself.
There are a couple of reasons you might be tempted to try this yourself:
- When you compile something locally, you end up with a version of the software much more customized to your hardware, which may yield some performance gains (in contrast, pre-compiled binaries often target the “least common denominator,” and may not take advantage of more high-end machines).
- Compiling from the source also gives you the ability to enable or disable certain features of the software. While in some cases it involves changing code, in some cases, it’s as easy as adding or removing a flag from the build command(s).
- Lastly, it never hurts as members of the free software community to explore how all these great applications are made. While compiling from an archive of the original source code may be beyond what a normal user does, using source packages provides a peek into the development and compile process for we mere mortal users.
Structure of DEB Source Packages
When you go to download a DEB source package from a repository, the package manager will be dealing with three primary files (shown in the Ubuntu repository below):
- [package name]_[version number].orig.tar.gz: This file contains the source code from upstream, or the original program’s developers.
- [package name]_[version number]build1.debian.tar.gz: This archive contains the code above, with any modifications necessary to make it compatible with DEB-based systems.
- [package name]_[version number]build1.dsc: A description of the files in the package, which may also include a signature.
Installing DEB Source Packages
The DEB system and its companion tools make it very easy to download and compile versions of software from APT repositories. The following steps describe the process:
First, you’ll need to install some software that allows you to compile other software. Issue the following command from the terminal:
sudo apt-get install build-essential
You’ll also want to make sure you have the source repositories enabled.
Check out the “Software Sources” in your package manager to confirm the “Source Code” option is checked.
Alternatively, inspect the “/etc/apt/sources.list” file and confirm that the following lines appear without a “#” mark in front of them (if they do, simply remove it and save the file):
deb-src http://us.archive.ubuntu.com/ubuntu/ precise universe deb-src http://us.archive.ubuntu.com/ubuntu/ precise multiverse
apt-src tool is a version of “apt-get” that works on source packages. Install it with the following:
sudo apt-get install apt-src
Note: if you install this package first, it will also install the build-essentials package for you
Next, you may need to get some libraries or other software required to build the package you want (this is a dependency, but different from the dependency you may encounter when installing binary packages).
sudo apt-get build-dep [package name]
Now you can download the package. The following command will fetch the package for you, compile it, and install it automatically:
sudo apt-src --build install [package]
If you prefer to download the source package, either to take a peek inside, or to make some changes, you can download it then install it once it’s on your local system with the following:
sudo apt-src install [package name]
(This will download the source files above)
sudo apt-src build [package name]
(This will build the package from the downloaded files)
sudo dpkg -i [package file name(s)].deb
Debian source packages and their related tools are a great way to begin learning about how free software is made. As a member of the community, you owe it to yourself to try it out, and learn an appreciation for all the hard work the developers put in.
Our latest tutorials delivered straight to your inbox