Select Page

Introduction

The rpmbuild command is used to create source code packages and or binary files for Linux Distributions like RedHat, CentOS, Fedora, etc. It is necessary for building RPM packages. initially, RPM packages were only meant to be used in RedHat Enterprise Linux. However, over time it got popular and found a place in other distributions like Fedora and OpenSUSE as well. It can be used from inside a folder or even directly from a tarball file without needing to extract it.

If you want to build an rpm package, you need to use the rpmbuild command. But to execute it, you first need to install it, as it is probably not installed in your system by default. It is commonly used in Redhat and Fedora, but you can also use this tool from other linux distributions and make rpm packages that you can later ship.

In this article, we’ll discuss how to fix the error of not being able to find the command in your Linux machine.


Install rpmbuild command

Fixing the error message can be as simple as just installing the package using your system’s package manager. The name of the package differs a bit from distribution to distribution, and so do the commands to install them.

In CentOS/RedHat

In CentOS and RedHat Linux, you have two different package managers that you can use to install the package. One is dnf and the other is yum. If you want to install the package using the dnf package manager, you’d use the following command:

$ sudo dnf install rpm-build

If you want to use the yum package manager instead, the command should look like this:

$ sudo yum install rpm-build

Nothing much of a difference between the two, but one thing you definitely need to make sure is to include the hyphen (-) in the package name, as simply searching for rpmbuild without the hyphen will return you a package not found error. Wow. Now there are more errors to face, isn’t it?

But hopefully, you should now be able to execute the rpmbuild command in your CentOS/RedHat Linux machine. Why not try it out?

In Fedora

To be able to use the rpmbuild command in Fedora, you need to install a few packages. To do this, execute the following package in your fedora Linux terminal:

$ sudo dnf install fedora-packager rpmdevtools

Or you can only download the rpm-build command using:

$ sudo dnf install rpm-build

In Arch Linux

In Arch Linux, there is a package called rpm-tools which contains the rpmbuild command along with many others. To beagle to use the rpmbuild, command, install that package using:

$ sudo pacman -S rpm-tools

Afterwards, you’ll be able to compile packages for RedHat and other Linux distributions that support RPM packages, and ship the packages to those systems for later use.


Fix the Path Variable

It is also possible that despite having the package installed in your machine, you’d still not be able to execute the rpmbuild command. This can happen due to your system’s global path variable not set correctly. Usually, this path is under /usr/bin, where most of the programs you install in your system reside. If for some reason, your path variable got altered and does not have the path variable set to scan this path, you’ll probably not be able to run the rpmbuild command, let alone others, as bourne again shell will not be able to scan for it while startup. If rpmbuild is installed in some other directory which is not scanned by the path variable, then you need to set it up manually as well.

To make the path variable scan the /usr/bin folder, add the following line in your .bashrc file, which should be located in your user’s home directory:

export PATH=$PATH:/usr/bin

If the rpmbuild command is installed in some other directory, make sure to add this line as well:

export PATH=$PATH:<path/to/installation/folder/>

In the above line, make sure to replace the <path/to/installation/folder/> with the actual path where the command is installed, instead of copy pasting it directly. 

Also, if you’re using some other shell than bourne again shell, than instead of .bashrc, you’ll need to include this command in the configuration file for that specific shell instead.

This should hopefully fix your issue with the rpmbuild command, if the previous method didn’t.


Rpmbuild vs Make

This is a very competitive topic, I’d say. While most people would recommend you to use rpm packaging using the rpmbuild command instead of using make, there are a couple of things you should consider. Firstly, using make is distribution independent. Packages that require using the make command generally have the dependencies required packaged in the source code. This does increase the file size, however. On the other hand, an rpm package will generally contain the commands that redirect the terminal to install those dependencies for you. 

The main thing to note here is not this, but instead, general usability. While creating packages that can be compiled using make can save you from needing to build several different packages for all the different distributions, it can get kind of cumbersome to maintain, as make won’t allow you to regulate updates and changes that easily. On the other side of the spectrum, using rpm packages will ensure that you can easily update your code projects and maintain their dependencies without any conflicts.

Both have their flaws and their goods, so it depends on what you want to achieve. Keep in mind that an rpm package will only be applicable in distributions that support them, such as Redhat and CentOS. Other than that, as long as you’re only targeting those specific systems, rpmbuild is definitely preferable to using make. 


Conclusion

It should at least be fine for me to expect that you have successfully been able to solve the issue of not being able to execute the rpmbuild command. Part of the reason why many new users are discouraged from using Linux is proven here. The fact that a given package differs from distribution to distribution, and the famously quoted dependency hell. These two live up to their might of keeping Linux users tough. Those who have full control over this perplexity are far more superior in terms of what they can extract from their usage of a computer. Pretty banal stuff, isn’t it?