CentOS 8 Package Management with dnf Package Manager

29/12/2020
DNF is simply the next generation package manager (after YUM) for RPM based Linux distributions such as CentOS, RHEL, Fedora etc.  In this article, I am going to show you how to use the DNF package manager for CentOS 8 package management. So, let’s get started.

Updating Package Repository Cache:

You can update the DNF package repository cache with the following command:

$ sudo dnf makecache

DNF package repository cache should be updated.

Listing Enabled and Disabled Package Repositories:

You can list all (enabled and disabled) the package repositories available on your CentOS 8 machine with the following command:

$ sudo dnf repolist –all

As you can see, all the enabled and disabled package repositories are displayed. On the repo id column, you have the Repository Id which you can use with the DNF –repo option. In the status column, you can see which repository is enabled and how many packages that particular repository has.

The same way, you can list only the enabled repositories as follows:

$ sudo dnf repolist –enabled

The same way, you can list only the disabled repositories as follows:

$ sudo dnf repolist –disabled

Listing All Available Packages:

You can list all the packages in all the package repositories with the following command:

$ sudo dnf list –all

The list is very long.

As you can see, it’s about 6419 packages in total.

$ sudo dnf list | wc –lines

You can use grep or egrep to search for packages in the list as follows.

$ sudo dnf list | egrep searchTerm

Here, I searched for tree package as you can see in the screenshot below.

$ sudo dnf list | egrep ^tree

Listing All Installed Packages:

You can list only all the installed packages as follows:

$ sudo dnf list –installed

The list is very long as well.

Searching for Packages:

You can search for packages by their package name and summary as follows:

$ sudo dnf search "Programming Language"

The search result should display all the matched packages. You can choose what to install from here.

Searching for Packages in Specific Repositories:

You can search for packages by their package name as follows:

$ sudo dnf repoquery *kvm*

As you can see, all the packages that has kvm in the package name is listed.

You can also use –repo option to define which package repository to search as follows:

$ sudo dnf repoquery *centos* >–repo extras

$ sudo dnf repoquery *centos* –repo BaseOS

As you can see, two search query returned different results because they are from different package repository.

Searching for Packages that Provides Specific File:

Let’s say, you need a file or command but you don’t know what package to install. You can search by full or partial file path to find the package name as follows:

$ sudo dnf provides */ifconfig

As you can see, net-tools is the package that provides the /usr/sbin/ifconfig command.

You can find the package name that provides the tree command as follows:

$ sudo dnf provides */bin/tree

You can also search for packages that provide a specific library file as follows:

$ sudo dnf provides */libssl.so*

As you can see, the package name and which package provides which version of the library is listed.

Learning More about Packages:

You can learn more about a package as follows:

$ sudo dnf info tree

As you can see, the package version, summary, description, size, repository information and many more is listed.

Installing Packages:

You can install a package (let’s say, httpd) as follows:

$ sudo dnf install httpd

It will show you what dependencies it will install, the total number of packages it needs to download, the total download size, total size after installation etc.

To confirm the installation, press Y and then press <Enter>.

The package should be installed.

Reinstalling Packages:

You can reinstall a package as follows:

$ sudo dnf reinstall httpd

Now, press Y and then press <Enter> to confirm the reinstallation.

The package should be reinstalled.

Removing Packages:

You can remove a package as follows:

$ sudo dnf remove httpd

It will show you what package dependencies will be removed, how many packages will be removed and how much disk space will be freed.

To confirm the removal, press Y and then press <Enter>.

The package along will all its dependencies should be removed.

Doing a System Upgrade:

You can check for whether software updates are available with the following command:

$ sudo dnf check-update

If there are any software updates, it will be listed.

You can do a minimal software update with the following command:

$ sudo dnf upgrade-minimal

Minimal software update will only install absolutely required security patches.

At this time, I do not have any.

For full system update, run the following command:

$ sudo dnf upgrade

It will show you a summary of what packages will be upgraded, how many packages will be installed, how many will be upgraded, the total download size etc.

To confirm the system upgrade, press Y and then press <Enter>.

It will download and install the software updates.

Clear Caches:

You can clean DNF package caches with the following command:

$ sudo dnf clean all

All the available caches should be removed.

Remove Unnecessary Packages:

You can remove unnecessary packages if available to save disk space as follows:

$ sudo dnf autoremove

At this time, I have no unnecessary packages on my CentOS 8 machine.

So, that’s basically how you use DNF to manage packages on CentOS 8. It’s very similar to YUM. Thanks for reading this article.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

[CI/CD] Phần 1: Hướng dẫn cài đặt Gitlab trên CentOS 7

Gitlab là một mã nguồn mở của máy chủ Git để quản lý mã nguồn dự án được sử dụng rộng...
30/12/2020

Redmine – Hướng dẫn cài đặt Redmine trên CentOS 7

Redmine là một ứng dụng nguồn mở sử dụng để quản lý dự án và kiểm soát các vấn đề liên...
30/12/2020

[Zabbix] Cài đặt Zabbix Server phiên bản 4.4 trên CentOS7

Zabbix là phần mềm nguồn mở sử dụng để giám sát hệ thống với nhiều công cụ hỗ...
30/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Mua proxy v4 chạy socks5 để chơi game an toàn, tốc độ cao ở đâu?
18/05/2024

Thuê mua proxy Telegram trọn gói, tốc độ cao, giá siêu hời
18/05/2024

Thuê mua proxy Viettel ở đâu uy tín, chất lượng và giá tốt? 
14/05/2024

Dịch vụ thuê mua proxy US UK uy tín, chất lượng số #1
13/05/2024

Thuê mua proxy Việt Nam: Báo giá & các thông tin MỚI NHẤT
13/05/2024