
dnf tips and tricks
- dnf tips and tricks
- Listing Packages Installed
- Listing Packages available
- Checking Package Information
- Checking for Security Updates
- Cleaning DNF Cache
- Searching DNF history
- Searching a Package
- List active repositories
- Enable/Disable a repository
- Update while excluding a package
- Adding a repository manually
- Adding Repositories with DNF config-manager
- Removing Repositories
Listing Packages Installed
sudo dnf list installed
Listing Packages available
sudo dnf list available
Checking Package Information
To check detailed information about a package, use the dnf info command:
# sudo dnf info nano
Installed Packages
Name : nano
Version : 5.6.1
Release : 5.el9
Architecture : x86_64
Size : 2.7 M
Source : nano-5.6.1-5.el9.src.rpm
Repository : @System
From repo : anaconda
Summary : A small text editor
URL : https://www.nano-editor.org
License : GPLv3+
Description : GNU nano is a small and friendly text editor.
Checking for Security Updates
Use the ‘–security’ flag with the updateinfo command to see if there are any security updates available.
sudo dnf updateinfo --security
Cleaning DNF Cache
DNF keeps a cache of the package metadata to speed up operations. However, it can sometimes become outdated. You can clean the cache using dnf clean:
sudo dnf clean all
Searching DNF history
DNF provides the history command as a means to monitor the activities executed by DNF. This can assist in the troubleshooting process should any issues arise.
sudo dnf history
Searching a Package
To search for a package, use the dnf search command. For example, to search for packages related to Python:
sudo dnf search python
List active repositories
# dnf repolist
Updating Subscription Management repositories.
repo id repo name
code Visual StudioCode
codeready-builder-for-rhel-9-x86_64-rpms Red Hat CodeReady Linux Builder for RHEL 9 x86_64 (RPMs)
copr:copr.fedorainfracloud.org:cboxdoerfer:fsearch Copr repo for fsearch owned by cboxdoerfer
epel Extra Packages for Enterprise Linux 9 - x86_64
rhel-9-for-x86_64-appstream-rpms Red Hat Enterprise Linux 9 for x86_64 - AppStream (RPMs)
rhel-9-for-x86_64-baseos-rpms Red Hat Enterprise Linux 9 for x86_64 - BaseOS (RPMs)
rhel-9-for-x86_64-supplementary-rpms Red Hat Enterprise Linux 9 for x86_64 - Supplementary (RPMs)
Enable/Disable a repository
Enable a repository
# dnf config-manager --set-enabled <repo>
Disable a repository
# dnf config-manager --set-disabled <repo>
Update while excluding a package
# dnf update -y --exclude "code"
Adding a repository manually
# cat /ec/yum.repos.d/pel.repo
[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
#baseurl=https://download.example/pub/epel/$releasever/Everything/$basearch/
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=1
gpgcheck=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$releasever
Description of each line
`epel`: Is the repository ID.
`name`: The human-readable name of the repository.
`baseurl`: The URL for the repository.
`enabled=1`: This enables the repository. To disable, change this to 0.
`gpgcheck=1`: This enables GPG signature checking. To disable, change this to 0.
`gpgkey`: The URL for the GPG key that should be used to sign the packages.
Adding Repositories with DNF config-manager
Before proceeding, ensure the dnf-plugins-core package is installed in your Fedora system. If not, you can install it using:
sudo dnf install dnf-plugins-core
Adding Repositories with DNF config-manager:
Let’s say you want to add a repository from the URL http://www.example.com/myrepo/.
With dnf config-manager, it’s as simple as this:
sudo dnf config-manager --add-repo http://www.example.com/myrepo/
The above command will create a .repo file under /etc/yum.repos.d/ for you.
Removing Repositories
sudo rm /etc/yum.repos.d/MyRepo.repo