1. Introduction

Package files are the base units of software in the Linux packaging system. Basically, it’s a compressed group of files that may comprise:

  • a number of programs
  • data files that support the programs
  • package metadata
  • package pre-installation and post-installation scripts

In this tutorial, we’ll see how to remove a specific type of package from a Linux system.

2. RPM Package Manager

RPM stands for Red Hat Package Manager. It provides the standard way to package software for the Red Hat Enterprise Linux (RHEL) distribution and its close relatives Fedora, CentOS, and OpenSUSE.

Also, Linux package management systems usually consist of two types of tools:

  • low-level tools to perform tasks such as installing and erasing package files
  • high-level tools that carry out dependency resolution and metadata searching

While all Red Hat-style Linux distributions use the same low-level program rpm, the high-level tools are not the same. Next, we’ll talk about the high-level program dnf, which the Red Hat Enterprise Linux and CentOS use.

3. Removing RPM Packages With dnf

Notably, we can uninstall or remove software using high-level or low-level tools. Dandified Yum (DNF) is a high-level software package tool for RPM-based Linux distributions. It’s the new-age version of the popular Yum package manager.

We can use the dnf program to remove a single package or a list of packages. To uninstall a particular software package, let’s run the following command as a superuser:

$ sudo dnf remove package_name

Critically, the RPM package name differs from the RPM package file name. In fact, the package file names consist of five elements:

  • package name
  • version
  • release
  • architecture
  • .rpm suffix
RPM package file name

Further, we can remove multiple packages at once by adding more package names to the command. For instance, the following command removes the packages listed after the remove keyword:

$ sudo dnf remove vidutils rhyme zipper

Here, we only need the package name to remove a package from our system.

However, erasing a package using dnf may also remove other packages that depend on it. We’ll employ the low-level tool rpm in a later section to remove a package without touching its dependencies.

4. Removing RPM Packages With rpm

Unlike dnfrpm can remove a package without removing packages that depend on it. In other words, the rpm program doesn’t handle dependency resolution.

To erase a program with rpm, we run the rpm command with the -e flag:

$ sudo rpm -e util-linux

Usually, if other packages need the one we’re uninstalling, rpm -e will fail. Consequently, it produces an error message. A successful uninstall produces no output.

Still, programs in Linux are hardly stand-alone. Instead, they often rely on the presence of other software units. Hence, the system blocks operations that would cause problems from completion like:

  • removing a package that another package depends on
  • installing a package when the system needs initial software to run the package

For example, we can see the Failed dependencies error in the following command output:

$ sudo rpm --test -e xz

error: Failed dependencies:
xz is needed by (installed) pcp-5.1.1-4.el8_3.x86_64
xz is needed by (installed) sos-3.9.1-6.el8.noarch
xz is needed by (installed) gettext-devel-
xz is needed by (installed) libreport-2.9.5-15.el8.x86_64
xz is needed by (installed) dracut-049-95.git20200804.el8_3.4.x86_64
xz is needed by (installed) libvirt-daemon-driver-qemu-6.0.0-28.module+el8.3.0+7827+5e65edd7.x86_64
xz is needed by (installed) rpm-build-4.14.3-4.el8.x86_64
xz is needed by (installed) libguestfs-1:1.40.2-25.module+el8.3.0+7421+642fe24f.x86_64
xz is needed by (installed) sysstat-11.7.3-5.el8.x86_64
/usr/bin/xz is needed by (installed) file-roller-3.28.1-3.el8.x86_64

The –test flag with -e checks if the erase command would succeed or fail without actually doing the uninstall. If the process is successful, rpm prints no output.

5. Removing RPM Packages Forcefully

Indeed, we can force rpm to remove a package that gives us a Failed dependencies error. To do so, we include some options in the rpm command:

$ sudo rpm -e --allmatches --nodeps --noscripts --notriggers --test PACKAGE_NAME

Here are the roles of the flags in the command:

  • PACKAGE_NAME – the name of the package to work with
  • -e or –erase – removes the package
  • –allmatches – removes all versions of packages that match the PACKAGE_NAME
  • –nodeps – prevents dependency checks
  • –noscripts – blocks the command from executing scriptlets around the package processing
  • –notriggers – similar to –noscripts,  stops the command from triggering scripts
  • –test – checks if the uninstall would succeed or fail without actually performing actions

In addition, using the –nodeps flag may cause other programs on the system to stop working. Essentially, installing or removing packages with rpm –nodeps can cause applications or the system to malfunction or crash.

Further, in critical cases, fixing such problems may require us to reinstall the operating system or boot into a rescue environment.

Because of this, it’s usually better to use package management with dependency resolution, regardless of the difficulties it may pose.

6. Conclusion

In this article, we saw the ways to remove an RPM package from the Linux system. Also, we learned how to remove an RPM package with dependencies forcefully.

We understood that the Dandified Yum package manager can carry out dependency resolution by fetching packages from online repositories, making it safer than using the low-level rpm directly.

Comments are closed on this article!