Over the past few years, installing software on Linux has gotten much easier. Today, most Linux distributions support some kind of package management, such as RPMs, which can greatly simplify the installation process. Nevertheless, you should not underestimate the importance of knowing how to install source packages on Linux.
While being slightly more complex to work with, source installations are still one of the main benefits of running Linux. They enable you to tweak and customize software installation to your needs rather than rely on the preferences of those building preconfigured packages. Also, there are still some software programs that come only in source packages. For these reasons, it is essential that you have an understanding of how to install Linux software from source. This tutorial will help you become proficient with source installations.
Getting the source code
There are numerous places to locate source code packages, depending on the specific piece of software that you are looking for. For a widely used program such as Sendmail, you can download source packages from a commercial site (sendmail.org, in this case), as well as from a variety of mirrored FTP and HTTP sites throughout the world. Smaller packages, on the other hand, may be available only on the developer’s Web site.
Most packages you encounter will have a number of possible downloads, from packages created for specific distributions such as RPMs or DEBs to precompiled binaries and, of course, the source code itself. Most of the source code you will encounter will be compressed into “tarballs.” This is simply a common way of packaging the code. These files will usually end with a .tar.gz extension.
Since the program tar itself does not do any compression, merely packaging, you will often see a .tar file run though gzip to slim it down, which is what adds the .gz extension to the end. These files can be unpacked with the command tar xpfz. Most developers will include a directory structure, so you shouldn’t have to create it manually. Having said that, it is still a good idea to uncompress the files into an empty directory, just in case.
For example, if I were going to download a Sendmail source package, I would first create a directory such as /usr/local/sendmail. Then, I would download the sendmail.8.12.0.tar.gz source package into that directory and unpack it by running tar xpfz sendmail.8.12.0.tar.gz from that directory.
You should also note that some Web browsers, such as Netscape, may attempt to automatically unpack the file when they notice the .gz extension. If you look in your download directory and see only a .tar file, don’t worry. Simply run tar xpf rather than tar xpfz to extract the files.
Installing from source
Once you unpack the source files, the first thing you should do is to check out the readme and install files prior to beginning the actual installation. Although many of the source packages you encounter will use the same commands, you'll run across sometimes major differences when you read these files. For instance, some software will contain an installation script that will do almost everything for you. Reading these files prior to installation will often save you time in the long run.
The usual method for installing source is to execute the following commands from the package directory:
The configure script will investigate your system and make sure that you have the needed components prior to attempting an install. It will check for such things as a compatible compiler and any required libraries. If there is anything missing, this script will let you know by outputting an error message. As a side note, this script will usually create a file called config.cache to store information from a previous attempt. If you have to install a missing dependency and need to rerun the configure script, use the rm command to remove the config.cache file first. That way, you'll ensure that the configure script checks everything again.
Here is a snapshot of a sample script execution:
creating cache ./config.cache
checking for gcc... gcc
checking whether the C compiler (gcc ) works... yes
checking whether the C compiler (gcc ) is a cross-compiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
checking for a BSD compatible install... /usr/bin/install -c
checking for socket in -lsocket... no
checking for strlcpy... no
checking for strlcat... no
checking for arc4random... no
checking for MD5Update... no
checking for warnx... yes
checking for libpcap... yes
checking for ANSI C header files... yes
checking for sys/ioctl.h... yes
checking for sys/time.h... yes
updating cache ./config.cache
Notice that not all options have a yes, and this does not necessarily kill the script. The script will let you know if you are missing a required item.
The next command, make, actually compiles the source code into an executable binary that can be installed on your system. This step may take a bit of time depending on the amount of source code and the speed of your system. If you’ve ever compiled a kernel, especially the latest ones, you know what I mean.
This is also the most likely time for errors to occur. Keep in mind that although developers try to make their source as widely usable as possible, there are so many varieties of Linux out there now that it’s hard to adjust the code for every possibility. If you encounter issues with library files, for instance, see if you have the complete developmental version of your Linux distro installed. This is where it can get tricky and where you tend to learn the most. The source code may be looking in the wrong place, it may be looking for an older library, or it could need a newer version of one.
If you run into error messages, the developer's Web site and the site for your particular distribution should be able to help you find any missing pieces you need in order to install the software. Also, don’t forget that searches on Google and Yahoo can be very valuable, especially for finding newsgroup posts. Odds are in your favor that someone else has had this problem before and that there is a resolution somewhere out there on the Internet.
Next, the make install command will take the compiled product of the source code, usually a binary and possibly some libraries, and install it onto your system. This basically entails copying the files into the appropriate directories so that they will be in your system’s path. These can usually be defined during the configuration stage. If you are unsure where the files went after this command, check the readme and install files for the defaults.
You can even examine the makefile that the configure script created to see what variables are stored there. Standard directories are usually /usr/local/bin, /usr/local/sbin, and /usr/local/lib. Again, this will vary depending on your system, and you may have to do some research.
You will probably need root access for the final command, as you may not have access to copy files into certain directories. An alternative is to run everything as root, but you might want to check the scripts first for security purposes. Remember that any command executed by a script as root will act just as if root typed it in at the command line. While this shouldn’t be an issue, especially with common packages downloaded from reputable locations, it is good to keep in mind.
The ability to download and install programs from the source code is one of the main benefits of running Linux. Even if you are not a software programmer, you can still control which options are compiled into your new software by installing from source. Some packages may have no other alternatives but source, and precompiled packages may not have every feature turned on. As a result, installing from source is a necessary skill to have as a systems administrator.
What tips do you have for installing from source?
We look forward to getting your input and hearing about your experiences regarding this topic. Post a comment or a question about this article.