Sunday, November 29, 2009

Junkless Software Installs From Source

On a recent podcast episode a listener wanted to know if there is "junk" in .rar and .tar files. I don't deal with .rar files very often, and usually .tar files are the normal way to distribute programs in source format for compiling and installing.

What are .rar and .tar files? RAR [1] is a proprietary archive and compression format. I don't believe much software for Linux is distributed in RAR format. If RAR is used to distribute files, there probably are not many non-essential files. TAR [2] is a program that archives files and Linux software is often distributed in this format. TAR is also used for backing up systems and other backup programs often use tar [3]. One note, TAR does not compress archives by default, but can compress and uncompress archives with options to the TAR command.

Back to the question of "junk" in TAR files. Usually the steps to compile and install software from source, distributed in a TAR archive, are:

  • Extract the archive - tar -zxf FILENAME
  • Run a configure script - ./configure
  • Compile the source code - make
  • Install the compiled program - make install
Once the software is installed the TAR archive may no longer be needed and can be deleted. If the author of the software created a rule to uninstall the software ($ sudo make uninstall) then the unarchived source may need to be kept. There is a better way to installing and managing source installed software.

Checkinstall [4] solves the problem by creating a software package that can be managed with your systems package manager. From the checkinstall web site:

Installs a compiled program from the program's source directory using "make install" or any other command supplied on checkinstall's command line. checkinstall will create a Slackware, RPM or Debian compatible package and install it using your distribution's standard package administration utilities.

Here are the steps to install a program distributed by source using checkinstall on a Ubuntu server. The example program is HTMLDoc [5], a program that converts HTML files to indexed HTML, Postscript or PDF.

First the gcc compiler and other utilities as well as checkinstall must be installed:

$ sudo apt-get install build-essential
$ sudo apt-get install checkinstall

The software must be downloaded, unarchived and configured:

$ tar -zxf htmldoc-1.8.27-source.tar.gz
$ cd htmldoc-1.8.27/
$ ./configure

The options to the tar command are, -z uncompress the gzipped archive, -x extract and -f the identified file. The -z option must be used if the archive is compressed with gzip, identified by the .gz extension.

Instead of using "$ sudo make install", the checkinstall command is used (a lot of output has been omitted):

$ sudo checkinstall
[sudo] password for srvadmin:

checkinstall 1.6.1, Copyright 2002 Felipe Eduardo Sanchez Diaz Duran
This software is released under the GNU GPL.

The package documentation directory ./doc-pak does not exist.
Should I create a default set of package docs? [y]: y
Preparing package documentation...OK
Please write a description for the package.
End your description with an empty line or EOF.
>> htmldoc_1.8.27
>> [CTRL]+D

**** Debian package creation selected ***

This package will be built according to these values:

0 - Maintainer: [ root@karmic ]
1 - Summary: [ htmldoc_1.8.27 ]
2 - Name: [ htmldoc ]
3 - Version: [ 1.8.27 ]
4 - Release: [ 1 ]
5 - License: [ GPL ]
6 - Group: [ checkinstall ]
7 - Architecture: [ i386 ]
8 - Source location: [ htmldoc-1.8.27 ]
9 - Alternate source location: [ ]
10 - Requires: [ ]
11 - Provides: [ htmldoc ]

Enter a number to change any of them or press ENTER to continue: [ENTER]
Done. The new package has been installed and saved to
You can remove it from your system anytime using:
dpkg -r htmldoc

Note that the description is entered and the defaults after that are used. Now the package is installed and .deb package (htmldoc_1.8.27-1_i386.deb) is created. The package can be saved and the rest of the source files and distribution archive can be deleted. The package can also be distributed and installed on other machines:

$ sudo dpkg -i htmldoc_1.8.27-1_i386.deb

Verification of the install can be done with the dpkg command:

$ dpkg -l htmldoc
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Description
ii htmldoc 1.8.27-1 htmldoc_1.8.27

The package can also be removed with the dpkg command:

$ sudo dpkg -r htmldoc

Additionally documentation for the installed software is saved in the /usr/share/doc/htmldoc directory.


No comments: