Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 18, 2024
Package files are the base units of software in the Linux packaging system. Basically, it’s a compressed group of files that may comprise:
In this tutorial, we’ll see how to remove a specific type of package from a Linux system.
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:
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.
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:
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.
Unlike dnf, rpm 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:
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-0.19.8.1-17.el8.x86_64
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.
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:
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.
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.