How to install Linux softwares from source code



Many Linux softwares come with easy to use package installer and dependency resolver that make software installation a lot easier and pain-free for the users. But, even with all the modern day utilities it is sometimes necessary or even advisable to compile/build the software from the source code. One reason for that is the packaged version of the program may not be available (yes! it still happens even these days) or sometimes building softwares from the source is rather preferable specially when building security critical applications.
Installing softwares from the source code is rather frowned upon, more than anything. Many people say it is confusing and hard, but all those are just myths. If you follow the instructions given within the source code you can install the software quickly and more easily. Most of the source codes can be built/compiled using the standard configure-make-make install method mentioned in this post, but it is always preferable to read the documentation of the software.

Tools needed for building/compiling from the source code

There are two categories of programs that you may need to build your softwares from the source code:
  1. Essential development tools required in all Linux systems
  2. Specific libraries or utilities on which the program, you are compiling, depends
Following are some standard development tools that you may need to build your software from the source code:

GNU coreutils

This is a large collection of essential system utilities: shellutils, fileutils, and textutils. (See http://www.gnu.org/software/coreutils/ for more info on coreutils.)

GNU binutils

Utilities releated to binary files (Details at http://www.gnu.org/software/binutils/).

gcc

GNU compiler collection, containing C, C++, Objective-C, Fortran, Java, and Ada, and libraries for these languages.

GNU tar

Archiving utility for source tarballs; these end in .tar.

gunzip

Compression utility often paired with tar. These end in .tar.gz.

bunzip2

A super-compression format for packing and unpacking tarballs; these end in .bz2.

make

This does the work of reading your configuration options and building the actual program files.
Note: Most of the Linux distributions have an option to install Core Development Tools so that you don't have to install them separately.
Files on which the program is dependent will be listed some where in the documentation of the source code.

The installation process

The standard way to compile and build a software, from source code, which comes in either tar.gz and tar.bz2 packages is as follow (again note that it is same in most of the softwares but documentation MUST be referred to before going any further.):
  • tar zxvf package-1.0.tar.gz (or tar jxvf package-1.0.tar.bz2)
  • cd package-1.0
  • ls
  • less README
  • less INFO
  • ./configure —help
  • ./configure
  • make
  • make install | tee install-output-makeinstall (this stores the installation output in the text install-output-makeinstall)
The above standard steps will help you install most of the softwares available, but you need to study your configure options carefully. So, make sure to read the configuration help file (using ./configure —help) before trying to install the software.

Advantages/Disadvantages of Compiling from the source

Advantages

  • You can set the exact configuration options
  • You can optimize the program for your specific architecture
  • You get ultimate control over the installation

Disadvantages

  • Updating or removing the softwares can be very hard
  • Dependency resolving can be very painful
  • Compiling the programs might take a lot of time

Iqrash Awan

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard.

1 comment:

  1. There is a mistake in a GNU coreutils URL (double "or"), which corrupts the link.

    ReplyDelete