Building Programs from Source on a Linux Server

The idea of building a program from source may seem overwhelming to you, and for most software installation on your server, you can avoid it.  Nevertheless, there may come a time when it is the best option or even the only option.  When that time comes, you will wish you kept reading this article.

Before you even begin the process of compiling source code, it is important to make sure you have the necessary development files in place. Many Linux distributions provide meta packages that will install the basic dev files with little effort. You may still need to meet other dependencies with specific software, but these meta packages will cover general compiling.

On Red Hat-based distributions like CentOS or Fedora, you need to run the following command as root:

yum groupinstall 'Development Tools'

This single command will install gcc, flex, rpm-build, automake, libtool, autoconf, gcc-c++, binutils, and other important packages, giving you a basic development system.

You are now ready to start building. The first thing you need to do is download the source code. You should start with something simple (i.e. don’t try compiling your kernel from source on the first go). To download it to your server, you can use wget:

wget http://hostingdomain.tld/downloads/files/thesourcecode.tar.gz

Next, extract the files to the directory of your choice and enter the source code directory:

tar zxvf thesourcecode.tar.gz

cd thesourcecode

Compiling C code with most programs is pretty simple from this point forward.  You only need three commands:

make install

It is possible that you could encounter errors along the way, especially in the “configure” stage. If you do, it will likely tell you if you are missing a dependency that you need to go back and install the development packages.  The best way to avoid this back and forth routine is to find out exactly what dependencies you need from the developer. They may have this information in their README file or on a site wiki.