DNF - Add a DNF repository
by
Jeremy Canfield |
Updated: March 24 2022
| DNF articles
There are two ways to add a repository to DNF.
- Add a .repo file to the /etc/yum.repos.d/ directory (preferred)
- Add a [repository] block to /etc/dnf/dnf.conf
Let's say you want to add the EPEL repository. Typically, this would be done by issuing the following command.
dnf install epel-release
Or like this.
dnf config-manager --add-repo https://www.example.com/epel.repo
This command will create the epel.repo file in the /etc/yum.repos.d directory.
~]$ ll /etc/yum.repos.d/
-rw-r--r--. 1 root root 1664 Apr 7 2020 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Apr 7 2020 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Apr 7 2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Apr 7 2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Apr 7 2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Apr 7 2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 7577 Apr 7 2020 CentOS-Vault.repo
-rw-r--r--. 1 root root 616 Apr 7 2020 CentOS-x86_64-kernel.repo
-rw-r--r-- 1 root root 1050 Oct 31 2020 epel.repo
-rw-r--r-- 1 root root 1149 Oct 31 2020 epel-testing.repo
Alternatively, you could manually create a repo file, such as foo.repo.
touch /etc/yum.repos.d/foo.repo
And then add something like this to the repo file. 1 means enabled, 0 means disabled.
[foo]
name=foo repository
baseurl=http://www.example.com/foo
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/foo
Did you find this article helpful?
If so, consider buying me a coffee over at