Let's say you need to install some software on CentOS which isn't available in the regular repositories. So you go and find yourself a copy of the source instead. Something that you just need to install using the commands:
./configure make make install
The only problem is that this doesn't allow you to uninstall the software easily. Nor does it permit you to distribute it to another machine that you may have. If you administer several machines at the same time, it can get quite complicated. I'd written an article earlier on how to build from source in a way that allows you to cleanly uninstall it later on using a package called "stow". However, the ideal would be to have a ".rpm" file ready so that you can install it using your regular package manager like "yum" or "dnf", as well as distribute it to other machines.
To my knowledge, there is only one package that comes close to creating an RPM file from source, without messing around with spec files etc. And that is checkinstall. Unfortunately, checkinstall seems to be bugged for .rpm files, and only creates .deb files without hassles. So in this article, I'll use a workaround with the following steps:
- Download and unzip the source;
- Use checkinstall to create a ".deb" file;
- Use alien to convert deb -> rpm
Step 1: Download tar.gz and Extract into Folder
As a test example, I'm going to use the software called "Singularity", which is used to create containers for software. To do this, use the "wget" command and extract it into a folder of your choosing. You can check out my written guide on installing software, and I show you how to do this in the first step.
Step 2: Install Checkinstall for your Linux Distro
Checkinstall isn't available in the regular repos for CentOS or RedHat. But we can find several versions on this website. Just type "checkinstall" into the searchbox, and you'll see the versions for CentOS as shown here:
Click through to the package you want and download the rpm file for checkinstall, and use your package manager to install it.
Step 3: Create a ".deb" File First
Ideally, we should be able to create a .rpm file directly from source with checkinstall. But as I said earlier, this seems to be bugged. So we have to create a deb file. To do this, first use the regular configure and make commands as usual from inside the source directory (the one you extracted into):
And then instead of "make install", just type:
This will then ask you what type of package you want to create. We want to create a .deb file, so type "D" when it asks you. You can try creating an RPM file directly and see if it works! You will then be asked to verify the information and start the creation process:
Once that's done, it will place the ".deb" file into the same directory as the source code.
Step 4: Convert the ".deb" file into a ".rpm" File
To do this, we're going to use a package called "alien". I've already written a tutorial on how using alien to do this. It's basically just one line. As mentioned in that article, the problem is that if you try and install the resulting rpm file, you will get transaction errors like this:
The article I mentioned shows you how to correct this error using the "rpmrebuild" tool and deleting the offending lines. Once that's done, you have a working RPM file:
And you can now install it using your regular package manager.
As you can see, it works! You have successfully created an RPM file from a tar.gz file in CentOS without the need for messy SPEC files and builds.