Posted on
Administration

Rolling back packages to previous versions

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

Rolling Back Packages to Previous Versions on Linux: A Comprehensive Guide

Dealing with software updates can sometimes lead to unforeseen issues, such as compatibility problems or software bugs. In scenarios where a new package version does not perform as expected, rolling it back to a previous state can be a crucial troubleshooting step. In this guide, we'll explore how to revert to prior versions of packages on Linux systems using different package managers: APT (used in Debian-based distributions like Ubuntu), DNF (used in Fedora), and Zypper (used in openSUSE).

Managing Rollbacks with APT

APT, or Advanced Package Tool, is the go-to package manager for Debian-based distributions. Here's how you can roll back a package using APT:

  1. Find the Version of the Package: Before rolling back, you need to know which versions of the package are available. You can list the available versions using the command:

    apt list -a package-name
    

    Replace package-name with the actual name of the package.

  2. Install the Previous Version: Once you know the versions, you can install an earlier version by specifying the version number:

    sudo apt install package-name=version
    

    For example, to install version 1.2 of example-package, you would use:

    sudo apt install example-package=1.2
    
  3. Prevent Automatic Updates: To prevent the package from being updated accidentally, hold it at the current version:

    sudo apt-mark hold package-name
    

    To unhold it later, you can use:

    sudo apt-mark unhold package-name
    

Managing Rollbacks with DNF

DNF is the next-generation package manager for RPM-based distributions like Fedora. Here’s how to perform a rollback:

  1. Undo the Last Transaction: If the unwanted update was recent, you can use DNF to undo the last transaction:

    sudo dnf history undo last
    

    This command reverts the most recent changes made by DNF.

  2. Rollback to a Specific State: Alternatively, you can rollback to a certain point in time (or transaction ID):

    sudo dnf history rollback transaction-id
    

    Replace transaction-id with the numeric ID of the desired state. To view the transaction history, you can use:

    sudo dnf history
    

Managing Rollbacks with Zypper

Zypper is the command-line interface of ZYpp package manager for installing, removing, and managing packages on openSUSE and SUSE-based systems. To roll back a package in Zypper:

  1. Find Out Available Versions: First, determine which versions of a package are available with:

    zypper se -s package-name
    

    This will list all available versions of the package in the repositories.

  2. Install an Older Version: To install an older version, specify the package name along with the version:

    sudo zypper install package-name=version
    

    You can replace version with the exact version number you wish to install.

  3. Lock the Package Version: To ensure that the package does not update in future operations, you can lock it:

    sudo zypper addlock package-name
    

    To remove the lock in the future, use:

    sudo zypper removelock package-name
    

Conclusion

Understanding how to revert to previous package versions is a valuable skill for any Linux user. It not only aids in troubleshooting but also ensures that you can maintain system stability and functionality even when newer software versions falter. Remember, always back up important data before making significant system changes like package downgrades or upgrades.

Rolling back packages can be a temporary measure while waiting for bugs to be fixed or incompatibilities to be resolved. Whatever your distro or package manager, the above guidelines will help you keep your system running smoothly.