Compile Software On Linux

The yum package manager on your Redhat or Centos server is a great tool for installing and updating software and libraries. However, the available software in the default yum repositories can be fairly dated, or not even contain the desired package.

Fairly often, the only viable option to installing a library or program, is to compile from it's source code package.

Installing prerequisites

Before we can begin, we must install some common system tools need for the compile processes:

yum install gcc gcc-c++ automake autoconf cmake expat-devel openssl-devel glibc-devel

These packages should cover the basic requirements for compiling most software. However, you'll likely encounter additional required headers or build utilities.

Use the below command to search for needed dependencies:

yum search package_name

Then install the required package(s) from the returned search results (packages generally required for compiling end in '-devel'):

yum install package

Compile, Configure, Install

Compiling and installation will usually involve these steps:

  1. Download
  2. Extract
  3. Configure
  4. Build
  5. Install

Note: The below steps will not always been 100% accurate. Be sure to always refer to the README and/or INSTALL text files provided by the package you are building.

Download

We must retrieve the source code package (most often a .tgz, .tar.gz, .tbz2, or .tar.bz2). Locate the URL to the desired package, copy it, and then use the 'wget' command to retrieve it to your server.

wget http://domain.org/download/package-0.8.tar.gz

Extract

Next, we'll need to extract the source code package:

tar -xzf nginx-0.8.tar.gz

If the package is of the format 'tar.gz' or 'tgz', use the switch '-xzf' with tar. However if the package is in a 'tar.bz2' or 'tbz2' format, use the switch '-xjf'.

Configure

The most crucial step of the compile process, is the configure stage.  Contained in package's directory should be a script 'configure', which is execute to scan your system for required dependencies and features.

./configure

You have the ability to customize the feature set and install options with the configure script. For details on available options, issue the command:

./configure --help

Then pass them to the script, for example:

./configure --enable-feature1 --disable-feature2 --with-library=/usr/lib/library

This script will generate the 'Makefile', which is used the build and installation steps.

Build

Once the source has been successfully configured, we'll need to actually compile the source code. Run the following command to do so:

make

This reads the 'Makefile' , which is generated during the configure stage, for instructions on how to compile the software.

Install

The final step, is to issue 'install' to the make command, which will read the Makefile for instruction on how to install the software to your server.

make install