在 Fedora 添加或移除软件源
本章节将讲述如何使用 DNF 添加、启用和禁用软件源。
Adding repositories
This section describes how to add software repositories with the dnf config-manager
command.
For Fedora 40 or earlier (DNF 4)
-
To add a new repository, do the following as
root
.-
Define a new repository by adding a new file with the
.repo
suffix to the/etc/yum.repos.d/
directory. For details about various options to use in the.repo
file, see the Setting [repository] Options section in the System Administrator’s Guide -
Add the repository with
--add-repo
, where repository is the file path:dnf config-manager --add-repo
repository
For example:
dnf config-manager --add-repo /tmp/fedora_extras.repo
-
For Fedora 41 or later (DNF 5)
-
To add a new repository, do the following as
root
.-
Define a new repository by adding a new file with the
.repo
suffix to the/etc/yum.repos.d/
directory. For details about various options to use in the.repo
file, see the Setting [repository] Options section in the System Administrator’s Guide -
Add the repository with
addrepo
, where repository is the file path:dnf config-manager addrepo --from-repofile=
repository
For example:
dnf config-manager addrepo --from-repofile=/tmp/fedora_extras.repo
-
Enabling repositories
This section shows how to enable a particular software repository by using the dnf config-manager
command.
-
To enable a particular repository, run the following command as
root
.dnf config-manager setopt repository.enabled=1
Where repository is the unique repository ID, for example:
dnf config-manager setopt fedora-extras.enabled=1
Disabling repositories
This section shows how to disable a particular software repository by using the dnf config-manager
command.
-
To disable a particular repository, run the following command as
root
.dnf config-manager setopt repository.enabled=0
Where repository is the unique repository ID, for example:
dnf config-manager setopt fedora-extras.enabled=0
Removing repositories
This section shows how to remove a Yum repository (or .repo
file).
If you know the ID of a repository, but you’re not sure what |
-
To remove a Yum repository, run the following command as
root
.rm /etc/yum.repos.d/file_name.repo
Where file_name is the name of the
.repo
file.
Want to help? Learn how to contribute to Fedora Docs ›