Posted on
Administration

Downgrading a package in APT

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

Mastering Package Downgrades in Linux: APT, DNF, and Zypper

In the world of Linux, package management is a core aspect of system administration and maintenance. While upgrading packages is a common task aimed at ensuring security and getting the latest features, there are times when you might need to downgrade a package. This might be necessary if an update introduces a bug, breaks compatibility, or negatively affects performance. Below, I'll guide you through downgrading packages using three popular package managers: APT (for Debian-based systems), DNF (for Fedora and other RPM-based systems), and Zypper (for openSUSE).

APT: Managing Packages in Debian, Ubuntu, and Derivatives

APT (Advanced Package Tool) is the go-to for managing packages on Debian-based systems like Ubuntu. Here’s how you can downgrade a package using APT:

  1. Check the Available Versions: First, you need to find out the available versions of the package you want to downgrade. You can do this with the command:

    apt show -a PACKAGENAME
    
  2. Downgrade the Package: Once you identify the version number to which you want to downgrade, use the following command:

    sudo apt install PACKAGENAME=VERSION
    

    Replace PACKAGENAME with the name of the package and VERSION with the specific version number you wish to downgrade to.

  3. Prevent the Package from Upgrading: If you want to prevent the package from being upgraded in future updates:

    sudo apt-mark hold PACKAGENAME
    

To unhold the package and allow it to receive updates again: sudo apt-mark unhold PACKAGENAME

DNF: Managing Packages in Fedora, RHEL, and Derivatives

DNF (Dandified YUM) is used primarily in Fedora and has replaced the older YUM in recent versions of RHEL and CentOS. Downgrading packages in DNF is straightforward:

  1. List the Available Versions: To see the available versions of a package to decide which one to roll back to, use:

    dnf --showduplicates list PACKAGENAME
    
  2. Downgrade the Package: To downgrade the package to a previous version:

    sudo dnf downgrade PACKAGENAME-VERSION
    
  3. Exclude from Future Updates: If you don't want DNF to automatically update the package to a newer version during a system update, add the following line to /etc/dnf/dnf.conf:

    exclude=PACKAGENAME
    

Zypper: Package Management in openSUSE

Zypper is the command-line interface of the ZYpp package management engine and is used in openSUSE. Downgrading a package involves similar steps:

  1. Finding Earlier Versions: Check the versions of the package available for installation:

    zypper se --details --versions PACKAGENAME
    
  2. Downgrade the Package: To install a specific previous version of the package:

    sudo zypper install PACKAGENAME=VERSION
    
  3. Lock the Package Version: To ensure that the package version remains unchanged during future updates:

    sudo zypper addlock PACKAGENAME
    

To remove the lock later: sudo zypper removelock PACKAGENAME

Conclusion

Downgrading packages can be as crucial as upgrading them, especially when stability and compatibility are at stake. Whether you're using APT, DNF, or Zypper, Linux provides you with robust tools to manage your system’s software effectively and maintain it in your required state. Always ensure to check release notes and maintain regular backups, especially when performing operations like downgrades that reverse standard system updates.