One of the regularly highlighted features of Linux is its open source heritage. Linux, and most of the software available for it, is distributed as source code. This source code needs to be compiled to machine code before it can be run on your computer. In this month's Here's How column, we look at the steps involved in compiling and installing software.
It is possible to get most of the software you will need in binary form. Programs in binary form usually come packaged as RPMs and are tailored for particular distributions of Linux. Compiling a program from source has several advantages:
- The program will be built and optimised for your particular system;
- There are often many configuration options available at compile time that are not available with software distributed as a binary;
- More programs are available; in particular, most pre-release software is not available in binary form;
- Many programs distributed in binary form may not be available for your distribution. Distributing software in source form ensures that the program will work on any distribution.
There are several steps involved in compiling and installing software, but it's not very hard to perform once you've done it once or twice. You will need development tools installed on your system; all distributions include them. This column is only a generic guide and these instructions may not work for all programs, but they will work without modification for most popular programs. When in doubt, consult the documentation for the program in question.
The first step in compiling a program is to configure it. Before performing the actual configuration, you should first read the documentation for the program. In the directory containing the source code there are likely to be files called README and INSTALL. Read them to determine whether this program has any particular requirements, and for general help if you encounter problems during installation.
Next, configure the build process. In the directory that contains the source code, type:
$ ./configure --help
This will return a list of all the configuration options available for the build process. Generally, the default configuration options are suitable for most systems. Many of these options will allow you to disable features that you may not want or that may be causing problems when compiling the program. Take note of any configuration options you would like to use and then configure the build process by typing:
$./configure <configuration options>
where <configuration options> are all of the options you have decided to use. The configure program will now perform a series of tests on your system to check that it will be possible to build the program. Some errors may occur; they usually mean you will need to install another piece of software to build the program. The configure program will provide some information on what is missing, and you must find and install these programs before you can continue the build process. If there are no errors, the build is properly configured and it is time to compile.
Now that the hard part is out of the way, compile the program by typing:
Compiling a program will take several minutes, at minimum, though it could take several hours depending on the size of the program and the speed of your system. The screen will slowly update as each piece of source code is compiled. When all are compiled they will be linked together to form the program.
If errors occur during compilation there is little you can do unless you know the programming language in which the program was written. If compilation fails, you can try using other configuration options or another version of the program.
Now that you have a properly built program, install it. As root, type:
# make install
This will make any directories needed on your computer and install the program in them. When this process is complete, you should be able to run the program by typing its name at the prompt. When you are happy that the program works properly, you can delete the directory the source code is in and continue to use the program.