Return to the Linux Tips
Compiling and installing from source files
By: Tony Steidler-Dennison http://www.lockergnome.com/issues/penguinshell.html Compiling and installing from source files generally encompasses five steps: download, untar, configure, make, and make install. Most will understand downloading. Untarring and unzipping a file can be a bit confusing, though. Like other Linux command line processes, there are quite a few options available to accomplish the task. Let's look at a few options to tar that are relevant: -x extract a file -f file -k keep old files; don't overwrite with new -v verbose; list files as processed -w interactive; confirm every action -z filter the file through gzip This is by no means a comprehensive list of options to tar. There are literally dozens more. When I've downloaded the file I want, I log in as root and cd to the /usr/local/src directory. Then, using four of the above options, I extract the file to the current working directory (usr/local/src), keeping the tar file's directory structure intact: tar zxvf /home/tony/src/somefile.tzr.gz This will create a directory in /usr/local/src (the current working directory) containing all the files. I cd to the directory, normally using command line completion to finish the directory name: cd som[tab] Generally, I take a look at any included README files in the source directory before beginning the compile and install. These are often explicit instructions from the program author as to how to best install and configure the program. They also provide insight into "gotchas" that may occur during the install. Inside the source code directory, there's normally a configure file. I can configure the program as is, or I can add some options to the configure command. For instance, if I want the program installed in the /opt directory rather than in /usr/bin, I can add the following: ./configure --prefix=/opt If I don't special configuration options (which may be covered, as well, in the README file), I can just configure: ./configure These configure files can do several things. First, they check your system for necessary libraries, exiting with an error if a library necessary to the operation of your program doesn't exist. Second, they create the Makefiles that will be used for the compilations process. If you've added options to the configure command, these will be taken into account when writing the Makefile. When the configure script has completed successfully, you're set for the actual compilation. Because the configure file has done its magic to create the Makefile, all you'll need to do is enter the command make. This is the compilation process. Depending on the size and complexity of the program you're compiling, this can be a short or very long process. You'll see all the commands to the compiler scrolling past, often too quickly to read. When the compile process completes successfully, you're but a step away from a running program. make install will install the program in the proper directory, often placing the executable binary in the PATH. This gives you the ability to run the program simply by typing in the program name. You can make the process even shorter, as well, by combining the make and make install commands: make && make install There's one drawback to combining these two commands: if either process fails, the build fails without an indication as to whether the failure was in the make or make install process.
[report a broken link by clicking here]