Compiling From Source In Linux

By Bhaskar Sarma | Published on Jan 01 1970
Compiling From Source In Linux

Apple iPhone XR 64GB at Lowest Price Ever

6.1" display | 50% Faster Graphics performance | TrueDepth camera

Click here to know more

Ever been too scared to install a program that wasn’t an RPM or DEB?

In Windows, installing software is a matter of clicks. In Linux, however, there are quite a few ways to skin the cat. Depending on the distribution you have, software can be downloaded in the form of either RPM or Deb packages. Again, you can compile software directly from source code—download the source code which comes in a tarball, unzip it and then compile it. In fact, this is the way source packages were distributed in the old days, and you might still have to go by this route in some cases. 

However, to most people out there, compiling from source still feels like voodoo. Here is a quick guide to all that you need to know about compiling from source and what goes behind the scenes, without leaving anything to chance.


Command to use: [tar xvzf mypackage.tar.gz] or [tar xvjf mypackage.tar.bz2]

This is the first thing to be done when you download the software. All the source files, associated libraries and documentation are distributed as compressed archives called tarballs. They are compressed using either gzip or bzip2, and hence the different extensions and the slightly differing switches used in the command.

After unpacking, a directory will be created with the name of the package in the destination folder. Change the directory using cd mypackage and then use ls to explore the directory tree. Make sure to read the readme, install and other documentation. Some packages might need some additional libraries or might suffer from dependency issues, so it makes sense to know what’s needed.


Command to use: ./configure

After you have unpacked the tarball and have also solved any dependency issues by installing required libraries it’s time to go to the next step: configuration. You have to run the command while inside the installed package directory. This command does not change anything substantially. It basically does a housekeeping job, checking whether all the required resources in the form of system libraries are present and then assigning values for system dependent variables. Various switches can be used along with the ./configure command to change the behaviour of the program. For example, appending

-quiet would stop printing the checking… messages during the configure process. If you know what you are doing you can use -no-create to inspect the output files before they are created. Using -prefix=mydirectory you can change the path where the Makefile will be created. The sample output of a configure command will look something like this:

creating cache ./config.cache
checking for extra includes... no
checking for extra libs... no
checking for a BSD compatible install.../usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets ${MAKE}... yes
checking for working aclocal... found
checking for working autoconf... found
checking for working automake... found
checking for working autoheader... found
checking for working makeinfo... found
checking for a C-Compiler... 
checking for gcc... gcc

creating Makefile
creating kdevelop/Makefile
creating po/Makefile
creating kdlgloader/Makefile

creating config.h
After the ./configure command has run—during which you will see a bunch of messages scrolling up the screen in rapid fire sequence—a Makefile will be created. This Makefile is then used to build the binary which then needs to be installed.


Command to use: make

The make command uses the Makefile to create installable binaries. Binaries are the Unix equivalent of executables, or .exe files. The make command is time consuming and results in a whole bunch of messages scrolling across your screen. This part is going to take a lot of time, depending on the package being compiled as well as the system configuration. There will be another bunch of messages scrolling across the screen, sometimes with warnings about some resource being absent. If all is okay, it will display the command prompt. If however, there is some problem it prompts you with appropriate status messages.

Most of the errors in the compilation process are due to missing or incompatible libraries. Say you have a software that depends on GTK , with the latest version not present. You might then have to download it from the Web. For the most part, if your OS is new you won’t have any problems. However, you can always search software repositories provided by your OS vendor. Look for development versions which end with –devel.


Command to use: make install

The make install command is the equivalent of point and click routine on Windows. The installation time will again depend on how big the software is. Before doing this, you need to log in as root. Since you have followed the best practices and have up till now done everything from a user account type su (sudo for Ubuntu) and enter the root password. After getting administrator privileges use this command to install the software. You will have no glitches and every thing will work out fine. Don’t forget to log out by using exit when you are done.

The program will be usually installed in /usr/local/bin (check our Know More About on Linux Directory Structures in the February issue for more details). However, if you have specified a path during the configuration process, you will have to navigate to that directory to access the program. In most modern Linux distributions, you will see a graphical shortcut and will have to click there to launch the program. It’s that simple, really.

Oh, and if you need to uninstall the program just delete the binaries. In some cases, you could use the make uninstall command to uninstall the program. Get cracking.

Bhaskar Sarma

Digit caters to the largest community of tech buyers, users and enthusiasts in India. The all new Digit in continues the legacy of as one of the largest portals in India committed to technology users and buyers. Digit is also one of the most trusted names when it comes to technology reviews and buying advice and is home to the Digit Test Lab, India's most proficient center for testing and reviewing technology products.

We are about leadership-the 9.9 kind! Building a leading media company out of India.And,grooming new leaders for this promising industry.