11.04.2011

How to install a program from source in Linux


Installing software in Linux is not the nightmare that Linux virgins tend to believe. There are package managers, repositories and precompiled binaries that make this task much easier. So much easier and cleaner that in fact, you must always refer to these methods FIRST before even thinking about installing from the source code.

There are only two "last stands" situations in which I would install from source:

  • There are no repositories or pre-compiled packages (.deb/.rpm/.pet) available for my distribution. This is usually the case for lesser-known, recent software projects.
  • I am not satisfied with the way a program works, and wish to alter its behavior in the source code to fulfill my needs. This is even more rare, as Linux programs are usually highly customizable.


If your installation needs do not meet any of these two criteria, then DON'T install from source. Use your package manager. That said, let's begin. I'll use the Beaver text editor in my example:

Part 1: Obtaining and extracting the code

Source code comes bundled with many other files, such as configuration and readme files, in what we call a "tarball." A tarball is a compressed file (like zip or rar) and has an extension that is either .tar, .tar.bz2 or .tar.gz. When you choose to download the source code, this is what you get. For example, the Beaver text editor comes as the following file:

click to enlarge

Your archive manager should be able to extract the tarballs by default. After we have the source folder extracted, we need to set a proper working environment to process it. This means, a temporary source code directory. So, copy your source folder to this folder:


user@computer:/usr/local/src $ (may need to be root for that)

Or open your download folder in terminal and type:

 $ sudo cp beaver-0.4.1.tar.bz2 /usr/local/src 


click to enlarge
 Now the source code is ready to  be processed.

Part 2: Resolving the dependencies

Programs may depend on other programs to work, but when installing from a package manager, such dependencies are automatically resolved. Source Code won't do that. You will have to find out all dependencies and install those before compiling and installing from source. This is indeed the trickiest bit of the installation. For most of the part you need to use your intuition to find out the dependencies.

-Read all the README files bundled with the source code;
-Read the online documentation of the program;
-Search for installation tips online (forums, etc).

This is how the Source Directory should look like.
When you think that all the dependencies have been satisfied, it's time to check it. This is done through the 'configure' shell script that comes with the bundle. Open the source folder in terminal and type:

 $ ./configure 

Lines of code will rain down. What 'configure' does is check if everything needed for installation is correctly installed according to the desired configuration. Here's where you may feel free to configure the program to your needs. In case 'configure' returns something like this:

The dependency for 'intltool' has not been satisfied.
It's hinted that some dependency has not been satisfied. Use your intuition again to install the package that contains the program cited by the 'configure' script and try again, until it returns no error at all. In Beaver's case, this is how it looks like:

Beaver has met all the dependencies.

If you made this far, you're 90% done. The hardest part of the installation is done. You have clearance to compile the program.

Part 3: Compiling and Installing

Compiling is done through the command 'make' (may need to be root for that). Since everything according to the 'configure' script is good, you can go ahead and just type:

 $ sudo make 

Again, shit will scroll down your screen... Don't worry about it. When it's done, however, it means that the program has been compiled. Now all you need to do is proceed to the installation, through the following command:

 $ sudo make install 

Watch again lines scrolling down for a bit and surprise! Look what I found on my applications menu:


Have fun with your program - you earned it after all these steps...

Note: since you did not install through a package manager (you didn't enter apt-get, yum, rpm in the command line) you WILL NOT be able to receive any updates without recompiling a new source code release. Also, the package manager won't be able to uninstall it. You will have to open the source code directory in terminal and and enter the following command:

 $ sudo make uninstall 


Therefore MAKE SURE YOU DON'T DELETE THE SOURCE FOLDER after the installation!
Any doubt you may have, feel free to e-mail me.


Nov 2011 by Klaus Zimmermann
Contact me.

7 comments: