Most of the applications are available in the official repository of your Linux distribution. However, there are times when some of the applications you're installing haven't been updated in the repository & you want to get the latest version of that application.Learning how to install application from the source code comes handy during this time.
There are 6 steps to follow :
- Obtaining source code
- Unzipping source code
- Configuring source code
- Resolving dependencies (if any dependency is missing)
- Compiling the source code
- Installing the binaries
1) Obtaining source code :
Source code of the opensource application can be obtained from Github using git if the source is uploaded in Github, or you can even visit the official website of the application & download it's source code. In most case, you'll find source of opensource application from the official website, easily.
2) Unzipping source code :
The downloaded source code will be in .tar.bz2 or .tar.gz ,you need to extract the files within the tar ball & place it anywhere in the /home directory. Note that, it is not necessary to put the extracted source code in /home directory only. But, /home directory is usually selected by most of the user as it is convenient to access.
3) Configuring the source code :
Since you've downloaded the source code & extracted it in /home directory; Use cd (change directory) command to enter the directory where the source code is available.
For Example :
cd /home/user_name/extracted_sourcecode_folder
Now, before configuring the source code let's understand what is it.
'Configure' is the title given to the configuration script which is usually shipped in package alongwith the source code. The configuration script makes sure that all the required tools for the compilation is installed within the system or not. If the dependency is missing, the configuration script will give you error & you won't be able to compile the software unless all the missing dependencies are not met.
You can execute the configuration script using following command (Make sure you're in root) :
./configure
All source codes are not shipped with configuration script, In that case you've to access documentation of that specific application & manually check the required dependencies & whether all the dependencies are met or not.
4) Resolving dependencies :
After process of 'configuring', if any dependency is missing the compilation won't proceed. So, if the configuration script pops the dependency error, then install the missing dependency & execute the configuration script again ( i.e ./configure). After configure script is successfully executed, it will generate the 'Make' file which will be used for the compilation of the source code.
Configuration & resolving dependencies are most important part of entire process as you've to match all the required dependencies, after that everything is cake walk.
Now if all the dependencies are met, you can proceed the next step.
5) Compiling the source code:
Now open terminal & type
make
This command will compile the software & all the binaries are generated. The duration taken by the system for compilation process depends on the size of the program & processing speed of your computer hardware. Now, we have to install the generated binaries created after compilation.
6) Installing the binaries :
If no error is invoked during the compilation of the software, open terminal/konsole & type :
make install
This command will install all the required binaries in the system.
Example for installing an application from the source code :
Following is the short example of the entire process of installing application from the source code. In this example, I will be installing 'elegance-colors' in my system.
Step 1 :
I have downloaded the source code of 'elegance-colors' from HERE
Step 2 :
Downloaded source code is extracted in /home directory
Step 3 :
I have to configure manually, since configuration script is not available for this opensource application.
Step 4 :
I resolved all the dependencies that were missing after checking the documentation. and proceeded to next step.
Step 5 :
Compiled the source code by typing
make
Step 6 :
Installed the compiled source code by typing
make install
and successfully installed the application from the source code.
This tutorial is containing the basics & simply gives hints on how you can compile any software from source code. There are many reasons by which error in configuring & compilation can occur & leaves you headbanging, like missing of shared libraries, no configuration script, unable to install dependencies ,etc. But somehow there's always a way to rectify the errors, if you know the basics.