Source compilation of a software package is something which we at InstaCarma need to do on a regular basis as part of our Server Management services for the Web hosting industry. Here is an overview of the process.

The need for source compilation

The first question that comes to the mind is that why compile a software package from source when it can be done easily via available RPMs. Well, the answer is that it gives you much more flexibility. Also, it is quite possible that the RPMs that you are going to use are outdated by a few weeks. Moreover, source compilation is a fairly straight forward process .


I am assuming that you have a system with required hardware and basic knowledge for working wth the OS (Linux) . Also, it is expected that you have the package containing the source code . Here , I would be talking about Apache. Other requirements are a compiler and utilities like make, tar , gunzip etc.

Step 1 : Extraction

The package is usually in a compressed tar archive ( also known as tarball) with extensions like tar.gz or tar.bz2

These can be unpacked by using the following commands :

For tar.gz,

$ tar xvzf abc.tar.gz

For tar.bz2,

$ tar xvjf abc.tar.bz2

This would usually create a directory with the name of the package (abc) . Please read any instruction files like README or INSTALL in this directory.

Step 2 : Configure

The source code usually contains a configure script which performs some checks and prepares the software for compilation.

Assuming that you are inside the directory, the configure script can be run by :

$ ./configure

This script will not compile anything . It checks the system that which compiler is available and whether the required libraries are present or not. Using this script we can also decide the location where apache will be installed and which optional modules need to be compiled. The script assigns values to the system-dependent variables which in turn are used to generate a Makefile. The Makefile generates the actual binary.

The list of options can be viewed by using :

$ ./configure –help

Step 3 : Make

The utility Make is used to build the binary. It uses the Makefile (generated in Step 2) located in the source directory. The Makefile has detailed step by step instructions on how to compile the software. A Makefile has set of rules in a typical format of target, dependency and the command. The advantage of using make is that if some of the source files are changed when the software is recompiled at some point , then only the files which are actually changed or the files which depend on the changed files will be recompiled.

For example, If a file has changed, each source file that includes the file must be recompiled to be safe. Each compilation produces an object file corresponding to the source file. Finally, if any source file has been recompiled, all the object files, whether newly made or saved from previous compilations, must be linked together to produce the new executable program.

Moving ahead, issue the following command :

$ make

This will start the compilation of Apache. The process time will depend upon your system capabilities.

Step 4 : Install

As root , run the following command :

$ make install

This will install Apache in the location defined by the configure script. You can ignore the weird messages as long as you do not stumble upon an error. Once the installation is complete, you can save some disk space by cleaning up the junk using :

$ make clean

Make sure that you keep the Makefile for future purposes.

That is it ! You can start Apache now.

Step 5 : Uninstall

For some reason, if you do not like the software then you can use :

$ make uninstall

If you come across any errors then you will have to manually remove the files. In case, you are unaware of the location then reading the Makefile will give you the answer 🙂

Contact Us On WhatsApp