Posted on
Administration

Disabling specific repositories temporarily

Author
  • User
    Linux Bash
    Posts by this author
    Posts by this author

How to Temporarily Disable Specific Repositories in Linux Using apt, dnf, and zypper

When managing packages on any Linux distribution, repositories are a crucial component. They are online sources from which packages are installed or updated. Occasionally, you may find the need to disable specific repositories temporarily. This might be necessary to troubleshoot conflicts, test software versions, or optimise system performance. Here, we'll explore how to temporarily disable repositories on various package managers, including apt (used by Ubuntu and other Debian-based distributions), dnf (used by Fedora and RHEL-based distributions), and zypper (used by openSUSE and SUSE Linux Enterprise).

1. Using apt on Debian-based Distros

Disabling a Repository

In Debian-based systems like Ubuntu, repositories are managed in the /etc/apt/sources.list file and additional /etc/apt/sources.list.d/ directory. To disable a repository:

  1. Open the Terminal: You can usually open it by pressing Ctrl+Alt+T.

  2. Edit the Source List:

    sudo nano /etc/apt/sources.list
    

    Alternatively, if the repository is in a separate file under sources.list.d, you can edit that file:

    sudo nano /etc/apt/sources.list.d/[filename].list
    
  3. Comment Out the Repository: Add a # at the start of the line of the repository you want to disable. For example:

    # deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted
    

    Save and exit the editor (Ctrl+X, then Y to confirm, and finally Enter).

  4. Update apt:

    sudo apt update
    

Re-enabling a Repository

Remove the # you added in the steps above and run sudo apt update to update the repository index.

2. Using dnf on Fedora or RHEL-based Distros

Disabling a Repository

With dnf, you can disable a repository without editing any files directly.

  1. List All Repositories:

    dnf repolist
    
  2. Disable the Repository Temporarily: To disable a repository during runtime (without altering configuration files), use:

    sudo dnf --disablerepo=repository_name install package_name
    

    Replace repository_name with the name of the repository and package_name with the name of the package you want to work with.

Re-enabling a Repository

Simply omit the --disablerepo option in your usual dnf command, or use --enablerepo=repository_name to re-enable it specifically for a transaction.

3. Using zypper on openSUSE or SUSE

Disabling a Repository

zypper makes it straightforward to manage repositories directly from the command line.

  1. List All Repositories:

    zypper lr
    
  2. Disable the Repository Temporarily:

    sudo zypper mr -d repository_name
    

    Replace repository_name with the exact name from the list you obtained.

Re-enabling a Repository

To re-enable, use:

sudo zypper mr -e repository_name

Conclusion

Disabling and re-enabling repositories is a common task in Linux system administration, helping in various maintenance and troubleshooting tasks. Regardless of which package manager your system uses, managing repositories efficiently allows for better control over the software sources and updates. Always ensure to re-enable any repositories you have disabled once you complete your tasks to keep your system in sync with the latest updates and security patches.