The word “compiling” intimidates a lot of novice or even intermediate users of Linux. In reality, compiling software packages on Ubuntu is not that difficult. In this post, we will explain what you need to know about compiling packages from source on Ubuntu. Some of the guides on htpcBeginner (installing CrystalHD, XBMC, etc.) talk about compiling packages from source on Ubuntu. We have more guides on the way that would require compiling packages as well. Therefore, we thought it is time to provide the new Linux users a very basic introduction to compiling packages from source on Ubuntu. So here it goes.
Why Do You Need to Compile Packages?
Compilation is the process of processing the source code (programming codes), customizing them to your environment (system/OS), and converting them to installable files. The packages available on Ubuntu repositories or the
.deb files are pre-compiled packages that you can install with a quick command. But many times some of the software packages available on the repository are older versions. Furthermore, some of the packages are not even available in the repositories. So if you want the latest and the greatest, you can download the latest source code, compile, and install it. While the process is longer than installing from the repositories, compilation makes that software the most responsive it can be for your system/environment. Once you know how to do it, it is an extremely easy process as, in most cases, all you have to do is issue a sequence of few commands.
Prerequisites for Compiling Packages from Source on Ubuntu
A typical user does not compile packages, therefore Ubuntu decided not to include the prerequisites for compiling packages into the distribution. The following command installs all the packages necessary for compiling packages on from Source on Ubuntu:
sudo apt-get install autoconf g++ subversion linux-source linux-headers-`uname -r` build-essential tofrodos git-core subversion dos2unix make gcc automake cmake checkinstall git-core dpkg-dev fakeroot pbuilder dh-make debhelper devscripts patchutils quilt git-buildpackage pristine-tar git yasm checkinstall cvs mercurial
This covers most common packages required for compiling downloaded packages, including those from SVN and Git.
Many of the source codes are downloaded as compressed
tar files. These can be extracted using the following commands:
tar -xzvf tarballname.tar.gz
tar -xjvf tarballname.tar.bz2
If the source code is from SVN or Git, the developers will provide instructions on how to get them. Typically for Git, the
git clone command is used. In our guides, we clearly specify the instructions on how to download from SVN or Git.
Compiling Packages from Source on Ubuntu
Compilation processes involves only 3 steps: configure, make, and install. The first step is
configure. Most downloaded sources (
tar files) will already have a
configure. To configure the compilation files issue the following command:
Some source codes downloaded from Git or SVN may not have the
configure. These will normally include a
autogen script which relies on
autoconf programs and will automatically build the configuration files and run the
The next step is to
make the installation files by compiling the source code, using the following command:
Depending on the size of the source code this step can take minutes to hours. If you have a multi-core process this can be done quicker by utilizing multiple cores. For example, if you have a quad-core processor you can use the following command instead: