Building from source in Linux

From GluCki
Jump to: navigation, search

In Linux, a software package is generally installed in two ways: a) Downloading and installing from official/unofficial repositories of respective distribution, or b) Downloading source code of software package, then building and installing it. The software package present in the respective online repository of a particular distribution are packaged and build according to that distribution structure and type. These packages are usually installed by a pre-installed utility, so no manual configuration is required. In order to install a software from source code, a series of instructions have to be followed.

Downloading the source code

The source code of desired software package can be downloaded from respective organization's website or from a VCS (like GitHub). The software packages are usually distributed in compressed tarball format (.tgz or .tar.gz). To extract the software files, the following command is required:

 tar xzvf software_pack.tar.gz

The tar utility uncompresses the file software_pack and creates a new folder named software_pack in the directory where the tarball was present. tar provides several other options, refer to GNU tar manual here.


Each software package is distributed with a configuration script with it. This configuration script runs several tests on the system to check whether the required dependencies for the software are present in the system or not. If a major dependency for the software is not present, the script displays an error message and the installation can not proceed further. If the tests were successful, the configuration script creates a file named Makefile in present directory, which contains several rules for the installation of software. For this step, directory is changed to software_pack. The software_pack directory should contain a configuration file. Then the following command is typed:


There are several other options that can be provided to configuration script, like where the software needs to be installed etc. For more information on configuration file, refer to this link.


The make utility comes embedded with most of the UNIX/UNIX-like systems. The make utility builds/compiles the software depending on the rules specified in the Makefile. The Makefile specifies the sequence that the make should follow to build several components/sub-programs of the software. The sequence depends on the implementation of software. The Makefile also provides path of libraries and headers on which the installation depends. If make runs successfully, the software has built succesfully (i.e. executables have been created) in the present directory. To build the software_pack, the following command is typed:


The Makefile should be present in the directory for make to work. For more information on make, refer to GNU make manual here.

make install

The Makefile contains several rules and labels to identify those rule. install is a rule specified in the Makefile. The install rule specifies the directories where the executables created during make should be copied. These directories are standard Linux directories where different components of installed software reside. For example, in most cases the executable is copied to /usr/local/bin, so that all users can use it and the libraries to their respective directory.