Home » Home Server » Basic guide to compiling packages from source on Ubuntu

Basic guide to compiling packages from source on Ubuntu

Compiling Packages from Source on Ubuntu

written by Anand June 8, 2013

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.

Compiling Packages from Source on Ubuntu

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.

Downloading Packages

Many of the source codes are downloaded as compressed tar files. These can be extracted using the following commands:

For tar.gz files:

tar -xzvf tarballname.tar.gz

For tar.gz.bz2 files:

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.

Recommended Guides:

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:

./configure

Some source codes downloaded from Git or SVN may not have the configure. These will normally include a autogen script which relies on automake and autoconf programs and will automatically build the configuration files and run the ./configure command.

./autogen.sh

The next step is to make the installation files by compiling the source code, using the following command:

make

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:

make -j4

The final step is to install the files generated by make command. The previous method of installing compiled files was using the following command:

sudo make install

It command puts the installation files under /usr/local/bin and you should be able to run it from there. You might still find the above command in some of the guides. Currently, the recommended way of installing compiled packages is using the checkinstall command:

sudo checkinstall

If checkinstall fails (due to some known bugs) you may need to run the following command instead:

sudo checkinstall --fstrans=0

This command takes you through a series of steps. If the documentation package directory is not available you will be asked to create one (doc-pack). Then you will be asked for a description for the package. Finally, a summary of the parameters that will be used to create the package will be displayed, as shown in the example below:

Check Install Build Package Parameters

Check Install Build Package Parameters

The compiled package will be installed and it will appear in the package manager (example: Synaptic) for clean, easy removal later. In addition, a .deb package will be created that you can use to install the package in other similar machines or the same machine in future without going through compilation again. That is it you are done compiling packages from source on Ubuntu.

Recommended Guides:

Troubleshooting

Many times configure script can stop with errors. This is usually due to missing dependencies. Read the error message to see if you need to install specific packages for the package you are compiling. Install those packages and reconfigure.

If the compilation errors out during the make process you can rerun after cleaning:

sudo make clean

Uninstalling Compiled Packages

The way you uninstall compiled packages depends on your method of installation. If you used checkinstall, you can uninstall the package from your package manager such as Synaptic. Or you could use one of the following commands:

sudo apt-get remove PackageName

or

sudo dpkg -r PackageName

If you used sudo make install, then navigate to your source code folder (where the compiled files reside) and run the following command:

sudo make uninstall

Upgrading Compiled Packages

If you installed from tar or SVN, you basically have to remove the previously installed packages, download the latest source code, compile, and install the latest version. If you installed from Git, it is essentially the same process but just a tad bit easier. Navigate to the source code folder and issue the following commands:

make distclean
git pull

The first command cleans out the previously compiled files and the git pull syncs with the Git repository and updates all the files that have changed since the last version. Then proceed with the normal configure, make, and install process.

Easy isn’t it. There are much more advanced ways of compiling packages from source on Ubuntu but hopefully this gave you a quick primer that should be enough to maintain a typical Linux home server.

IPVanish VPN Exclusive Offer - only $3.25/month:
VPN Guides
Windows, Android, Ubuntu
Kodi OpenVPN
OSMC on RPi
♦ Hide your browsing (no logs), Anonymize Streaming and Downloads
♦ Circumvent Geo/Country Restrictions and access worldwide content
♦ Works on Windows, Mac, Linux, Android, iOS, Router, and more
♦ Money back guarantee - Sign Up Now

Related Articles