DNF (Dandified YUM) can be considered as the updated version of the YUM utility. DNF utility stands far better than other package managers when it comes to memory usage, CPU utilization, and various other performance-related factors.
In this tutorial, let us discuss how to use dnf package management tool to remove packages with examples.
How to remove packages
Similar to package installation, DNF gives you the ability to remove packages that you no longer need on your computer. Similar to the install command all you need to do is identify the package then run the command in your terminal:
sudo dnf remove httpd
After this, packages related to httpd will be removed.
Note: Alternatively, we can use the 'erase' option in place of remove which will also uninstall the packages from the system.
dnf erase httpd
The above command removes all packages related to httpd and the output will be the same.
How to remove all packages from a selected repository
To remove all packages from a particular repository, we first need to get its repository id. To do that, we run the command below
dnf -v repolist
Sample Output
Loaded plugins: builddep, changelog, config-manager, copr, debug, debuginfo-install, download, generate_completion_cache, groups-manager, needs-restarting, playground, repoclosure, repodiff, repograph, repomanage, reposync
DNF version: 4.12.0
cachedir: /var/cache/dnf
Last metadata expiration check: 0:00:15 ago on Mon 01 Aug 2022 10:46:28 PM UTC.
Repo-id : fedora
Repo-name : Fedora 36 - x86_64
Repo-revision : 1651698971
Repo-updated : Wed 04 May 2022 09:16:11 PM UTC
Repo-pkgs : 67,992
Repo-available-pkgs: 67,992
Repo-size : 88 G
Repo-metalink : https://mirrors.fedoraproject.org/metalink?repo=fedora-36&arch=x86_64
Updated : Mon 01 Aug 2022 10:46:01 PM UTC
Repo-baseurl : http://mirror.fcix.net/fedora/linux/releases/36/Everything/x86_64/os/ (107 more)
Repo-expire : 604,800 second(s) (last: Mon 01 Aug 2022 10:46:01 PM UTC)
Repo-filename : /etc/yum.repos.d/fedora.repo
Repo-id : fedora-cisco-openh264
Repo-name : Fedora 36 openh264 (From Cisco) - x86_64
Repo-revision : 1649350358
Repo-updated : Thu 07 Apr 2022 04:52:38 PM UTC
Repo-pkgs : 4
Repo-available-pkgs: 4
Repo-size : 900 k
Repo-metalink : https://mirrors.fedoraproject.org/metalink?repo=fedora-cisco-openh264-36&arch=x86_64
Updated : Mon 01 Aug 2022 10:46:18 PM UTC
Repo-baseurl : https://codecs.fedoraproject.org/openh264/36/x86_64/os/ (0 more)
Repo-expire : 1,209,600 second(s) (last: Mon 01 Aug 2022 10:46:18 PM UTC)
Repo-filename : /etc/yum.repos.d/fedora-cisco-openh264.repo
Repo-id : fedora-modular
Repo-name : Fedora Modular 36 - x86_64
Repo-revision : 1651698710
Repo-updated : Wed 04 May 2022 09:12:01 PM UTC
Repo-pkgs : 825
Repo-available-pkgs: 0
Repo-size : 1.6 G
Repo-metalink : https://mirrors.fedoraproject.org/metalink?repo=fedora-modular-36&arch=x86_64
Updated : Mon 01 Aug 2022 10:46:19 PM UTC
Repo-baseurl : http://fedora.mirror.constant.com/fedora/linux/releases/36/Modular/x86_64/os/ (107 more)
Repo-expire : 604,800 second(s) (last: Mon 01 Aug 2022 10:46:19 PM UTC)
Repo-filename : /etc/yum.repos.d/fedora-modular.repo
As you can see in the output above, we have 2 repo-ids -fedora and updates.
Now you can proceed to remove all packages from a specific repository using the command below
dnf repository-packages repo-id remove
For example, If we want to remove all packages from fedora repository we run
dnf repository-packages fedora remove
Here, Fedora Linux is the repo-id.
Note:
For the parent repo-id's, you'll get an alert in the terminal that some packages are system protected. e.g.
dnf repository-packages fedora remove
Sample Output
Problem 1: The operation would result in removing the following protected packages: dnf, kernel-core, systemd, systemd-udev
Problem 2: The operation would result in removing the following protected packages: dnf, kernel-core, systemd, systemd-udev
Problem 3: The operation would result in removing the following protected packages: dnf, kernel-core, systemd, systemd-udev
Problem 4: The operation would result in removing the following protected packages: dnf, kernel-core, systemd, systemd-udev
How to list and remove packages
You can use the dnf list command to get a list of installed and available packages.
To generate a list of installed packages, run the command below:
sudo dnf list installed | cat -n
The argument 'cat -n' is used to number the packages on the terminal's output.
Sample Output
1 Installed Packages
2 ModemManager.x86_64 1.18.6-1.fc36 @fedora
3 ModemManager-glib.x86_64 1.18.6-1.fc36 @fedora
4 NetworkManager.x86_64 1:1.38.0-1.fc36 @updates
5 NetworkManager-bluetooth.x86_64 1:1.38.0-1.fc36 @updates
6 NetworkManager-initscripts-ifcfg-rh.x86_64 1:1.38.0-1.fc36 @updates
7 NetworkManager-libnm.x86_64 1:1.38.0-1.fc36 @updates
8 NetworkManager-team.x86_64 1:1.38.0-1.fc36 @updates
9 NetworkManager-wifi.x86_64 1:1.38.0-1.fc36 @updates
10 NetworkManager-wwan.x86_64 1:1.38.0-1.fc36 @updates
11 PackageKit.x86_64 1.2.5-1.fc36 @fedora
12 PackageKit-glib.x86_64 1.2.5-1.fc36 @fedora
13 abattis-cantarell-fonts.noarch 0.301-7.fc36 @fedora
14 abrt.x86_64 2.15.1-1.fc36 @fedora
15 abrt-addon-ccpp.x86_64 2.15.1-1.fc36 @fedora
16 abrt-addon-kerneloops.x86_64 2.15.1-1.fc36 @fedora
17 abrt-addon-pstoreoops.x86_64 2.15.1-1.fc36 @fedora
18 abrt-addon-vmcore.x86_64 2.15.1-1.fc36 @fedora
19 abrt-addon-xorg.x86_64 2.15.1-1.fc36 @fedora
20 abrt-cli.x86_64 2.15.1-1.fc36 @fedora
However, if you want to list the available packages for installation, run the command below:
sudo dnf list available | cat -n
The output is a long list use any filter such as more, less, or grep.
Sample Output
1 Last metadata expiration check: 0:08:34 ago on Mon 01 Aug 2022 10:46:28 PM UTC.
2 Available Packages
3 0ad.x86_64 0.0.25b-2.fc36 fedora
4 0ad-data.noarch 0.0.25b-3.fc36 fedora
5 0xFFFF.x86_64 0.9-4.fc36 fedora
6 2048-cli.x86_64 0.9.1-13.fc36 fedora
7 2048-cli-nocurses.x86_64 0.9.1-13.fc36 fedora
8 2048-cli-sdl.x86_64 0.9.1-13.fc36 fedora
9 2ping.noarch 4.5.1-2.fc36 fedora
10 389-ds-base.x86_64 2.1.3-2.fc36 updates
11 389-ds-base-devel.x86_64 2.1.3-2.fc36 updates
12 389-ds-base-libs.x86_64 2.1.3-2.fc36 updates
13 389-ds-base-snmp.x86_64 2.1.3-2.fc36 updates
14 3Depict.x86_64 0.0.22-11.fc36 fedora
15 3dprinter-udev-rules.noarch 0.2.2-7.fc36 fedora
16 3mux.x86_64 1.1.0-6.fc36 updates
17 3proxy.x86_64 0.8.13-7.fc36 fedora
18 4Pane.x86_64 7.0-4.fc36 fedora
19 4diac-forte.x86_64 1.12.0-7.fc36 fedora
20 4th.i686 3.62.5-9.fc36 fedora
21 4th.x86_64 3.62.5-9.fc36 fedora
22 4th-devel.i686 3.62.5-9.fc36 fedora
Autoremove Option
The autoremove option is used to uninstall packages that were initially installed as dependencies of installed packages but are no longer required by such packages anymore.
To uninstall the dependencies, run the command:
dnf autoremove
Conclusion
In this tutorial, we learned how to DNF to uninstall packages.
Thanks for reading and please share your suggestions and thoughts in the below comment section.
Comments