Skip to Content

Disable a specific repository in Linux when install a package

Disabling a specific repository while installing a package in Linux can be useful in various scenarios, such as avoiding packages from an untrusted or broken repository.

The exact method depends on the package manager you are using.

Here are methods for some of the most common package managers:

  1. APT (Debian, Ubuntu, and derivatives):
    • Temporarily Disable a Repository:
      • Edit the sources list: sudo nano /etc/apt/sources.list or the specific file in /etc/apt/sources.list.d/.
      • Comment out the repository line by adding a # at the beginning. For example, #deb http://example.com/ubuntu bionic main.
      • Save and exit the editor. Run sudo apt update to refresh the package lists.
    • Exclude a Repository using the -o option:
      • This option is more temporary and doesn’t require editing configuration files.
      • Use the command: sudo apt-get -o Dir::Etc::sourcelist=”sources.list.d/repository-to-exclude.list” install package-name.
      • Replace repository-to-exclude.list with the name of the file for the repository you want to exclude.
  2. YUM (CentOS, RHEL, Fedora ):
    • Using –disablerepo Option:
      • This option allows you to temporarily disable a repository during the execution of a particular command.
      • Use the command: sudo yum –disablerepo=repository-name install package-name.
      • Replace repository-name with the name of the repository you want to disable.
  3. DNF (Fedora and later):
    • Using –disablerepo Option:
      • Similar to YUM, DNF allows you to disable a repository temporarily for a single transaction.
      • The command is: sudo dnf –disablerepo=repository-name install package-name.
      • Here, repository-name should be replaced with the actual name of the repository you wish to disable.
  4. Zypper (openSUSE):
    • Using –disable-repositories Option:
      • Zypper allows disabling one or more repositories for a single command.
      • The command format is: sudo zypper –disable-repositories repository-name install package-name.
      • Replace repository-name with the repository’s name you want to exclude.
  5. Pacman (Arch Linux):
    • Temporarily Disable a Repository:
      • Open the Pacman configuration file: sudo nano /etc/pacman.conf.
      • Find the lines corresponding to the repository you want to disable and add a # at the start of these lines.
      • Save the file and exit. Note that you don’t need to run an update command as Pacman will do it automatically when you install or update packages.

After making these changes, you can proceed with installing the package, and the disabled repository will not be considered during the process. However, remember to revert any changes if you want to use the disabled repository in the future.