How to build a RPM or DEB package from the source with CheckInstall

Question: I would like to install a software program by building it from the source. Is there a way to build and install a package from the source, instead of running "make install"? That way, I could uninstall the program easily later if I want to.

If you have installed a Linux program from its source by running "make install", it becomes really tricky to remove it completely, unless the author of the program provides an uninstall target in the Makefile. You will have to compare the complete list of files in your system before and after installing the program from source, and manually remove all the files that were added during the installation.

That is when CheckInstall can come in handy. CheckInstall keeps track of all the files created or modified by an install command line (e.g., "make install" "make install_modules", etc.), and builds a standard binary package, giving you the ability to install or uninstall it with your distribution's standard package management system (e.g., yum for Red Hat or apt-get for Debian). It has been also known to work with Slackware, SuSe, Mandrake and Gentoo as well, as per the official documentation.

In this post, we will only focus on Red Hat and Debian based distributions, and show how to build a RPM or DEB package from the source using CheckInstall.

Installing CheckInstall on Linux

To install CheckInstall on Debian derivatives:

# aptitude install checkinstall

To install CheckInstall on Red Hat-based distributions, you will need to download a pre-built .rpm of CheckInstall (e.g., searchable from http://rpm.pbone.net), as it has been removed from the Repoforge repository. The .rpm package for CentOS 6 works in CentOS 7 as well.

# wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/ikoinoba/CentOS_CentOS-6/x86_64/checkinstall-1.6.2-3.el6.1.x86_64.rpm
# yum install checkinstall-1.6.2-3.el6.1.x86_64.rpm

Once checkinstall is installed, you can use the following format to build a package for particular software.

# checkinstall <install-command>

Without <install-command> argument, the default install command "make install" will be used.

Build a RPM or DEB Pacakge with CheckInstall

In this example, we will build a package for htop, an interactive text-mode process viewer for Linux (like top on steroids).

First, let's download the source code from the official website of the project. As a best practice, we will store the tarball in /usr/local/src, and untar it.

# cd /usr/local/src
# wget http://hisham.hm/htop/releases/1.0.3/htop-1.0.3.tar.gz
# tar xzf htop-1.0.3.tar.gz
# cd htop-1.0.3

Let's find out the install command for htop, so that we can invoke checkinstall with the command. As shown below, htop is installed with 'make install' command.

# ./configure
# make install

Therefore, to build a htop package, we can invoke checkinstall without any argument, which will then use 'make install' command to build a package. Along the process, the checkinstall command will ask you a series of questions.

In short, here are the commands to build a package for htop:

# ./configure
# checkinstall

Answer 'y' to "Should I create a default set of package docs?":

You can enter a brief description of the package, then press Enter twice:

Enter a number to modify any of the following values or Enter to proceed:

Then checkinstall will create a .rpm or a .deb package automatically, depending on what your Linux system is:

On CentOS 7:

On Debian 7:

Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.


Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

Leave a comment

Your email address will not be published. Required fields are marked *