sodcalculator

10 Tech How-To

Disable a Specific Repository in Linux When Installing a Package

Guide 10-31302 · Updated · Step by step

To disable a specific repository for a single package installation in Linux, you can use the --disablerepo option with dnf or yum on RHEL-based systems, or use a temporary apt configuration with -o on Debian/Ubuntu. This lets you install from a different repo without permanently removing or disabling the repository.

Why You Might Need to Disable a Repo Temporarily

Repositories are collections of software packages. Sometimes a specific repo provides a version of a package that conflicts with your system, is outdated, or is broken. You might want to install a package from the default repo instead, without permanently disabling the problematic repo. This is common when a third-party repo (like EPEL, RPM Fusion, or a PPA) offers a version that causes dependency issues or is not compatible with your distribution.

How It Works: Package Manager Options

Both major package managers have built-in flags to ignore a repo for a single command. On dnf and yum, the --disablerepo option takes the repo ID or a glob pattern. On apt, you use -o to override configuration values, including the list of enabled repositories.

Disabling a Repo with dnf/yum (RHEL, Fedora, CentOS)

To install a package while skipping a specific repo, use the --disablerepo flag. For example, to install nginx while ignoring the EPEL repository:

sudo dnf --disablerepo=epel install nginx

You can also use wildcards to disable multiple repos at once:

sudo dnf --disablerepo='*testing*' install nginx

To see the repo ID, run dnf repolist or yum repolist. The ID is the short name in the first column.

Disabling a Repo with apt (Debian, Ubuntu)

For apt, you can override the configuration that lists enabled repositories. The -o option lets you set any apt configuration value. For example, to install vim while ignoring a PPA named ppa:example/custom, you would use:

sudo apt -o Dir::Etc::sourcelist="sources.list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0" install vim

This is messy. A cleaner approach is to temporarily move the repo file or comment out the line, but that affects all subsequent commands. A better method is to use apt-get with a custom sources list file:

sudo apt-get -o Dir::Etc::sourcelist="sources.list.d/custom.list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0" update

Then install with the same options. However, this is complex for a single install. Most users prefer to temporarily comment out the repo line, run the install, then uncomment it.

How to Choose the Right Approach

If you are on a Red Hat-based system, --disablerepo is the cleanest and safest. For Debian-based systems, the -o override is possible but not user-friendly. Consider these factors:

  • Frequency: If you need to bypass a repo often, consider permanently disabling it and enabling only when needed.
  • Dependencies: Disabling a repo may cause the package manager to fail if the package is only available there. In that case, you might need to install from a local file or another source.
  • System updates: Temporarily disabling a repo for a single install does not affect future updates.

Common Problems and Misconceptions

A common mistake is using --disablerepo with apt; it does not work because apt uses a different syntax. Another issue is forgetting that --disablerepo only affects the current command, not the entire session. Some users think they need to edit configuration files, but the flag is much simpler. Also, if you disable a repo that provides a dependency, the install may fail with a “no package found” error. In that case, you may need to enable another repo or install the dependency manually.

Alternatives to Disabling a Repo

Instead of disabling a repo for a single install, you can:

  • Pin a package version: Use apt-mark hold or dnf versionlock to prevent updates from a specific repo.
  • Install from a local file: Download the .deb or .rpm and install with dpkg -i or rpm -i.
  • Use a different repo: Enable a more reliable repo temporarily.
  • Create a repo priority: Set higher priority for the repo you want to install from, so the package manager prefers it.

Safety and Best Practices

Disabling a repo temporarily is safe as long as you do not disable all repos or remove essential dependencies. Always ensure you have a valid alternative source for the package. Do not disable repos that contain security updates. If you are unsure, check the package availability with dnf list or apt-cache policy before installing.

Frequently Asked Questions

Can I disable a repo permanently for all commands?

Yes. For dnf/yum, edit the repo file in /etc/yum.repos.d/ and set enabled=0. For apt, comment out the line in /etc/apt/sources.list or a file in sources.list.d/. This affects all future commands.

What if the package is only in the disabled repo?

If you disable the only repo that has the package, the install will fail. You can either re-enable the repo temporarily or download the package file manually and install it with dpkg -i or rpm -i.

Does disabling a repo affect the system update?

No, the --disablerepo option only applies to the current command. System updates will still use all enabled repos unless you specify otherwise.

How do I find the repo ID?

For dnf/yum, run dnf repolist or yum repolist. For apt, run apt-cache policy or check the files in /etc/apt/sources.list.d/.

Can I disable multiple repos at once?

Yes, with dnf/yum you can use a comma-separated list or a wildcard, e.g., --disablerepo='repo1,repo2' or --disablerepo='*test*'.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →