How to downgrade a Package via apt-get

Estimated reading: 3 minutes 803 views

You can downgrade a recently updated package using the apt command in Ubuntu and Debian-based distros. Here’s how to do that

In a situation where a recently upgraded software is causing issues?

While you can always investigate the issue to fix it, at times, going back to the previous working version saves time and effort.

If the new version introduced a bug, you could do nothing on your end, right?

The good thing is that you can easily downgrade an apt package in Ubuntu and Debian.

All you have to do is to use the apt command like this:

# apt install package_name=package-version-number

That seems easy enough but how would you get the exact version number? Which old versions are supported? You can get that detail with:

# apt-cache policy package_name

Let me explain all this with a real-life example.

 1. Check the currently installed package version

Then check for the available versions that could be installed .

# apt-cache policy package_name

For example, to check the available versions of the package docker, you can run: apt-cache policy docker

It may throw a huge list or just a small one:

 

If it shows at least one older version than the current one, you are in luck.

Now, you may think that the version number of a package would be composed of just the numbers. But that may not always be the case.

Basically, you copy the entire stuff before 500 (the priority number)

2. Next, use the apt-get install command with the package name and version number to install the desired version

# apt install package_name=package-version-number

You’ll see a warning about downgrading the package, of course.

But once the process completes, your package would have been downgraded to the given older version.

After running the command, apt-get will download and install the specified version of the package. Note that if the downgraded version has any dependencies that conflict with the current installed version, you may need to resolve those conflicts before the downgrade can proceed.

3 . Finally, prevent the package from being upgraded to the latest version by adding it to the hold list using the apt-mark command.

# apt-mark hold package_name

For example, to prevent docker from being upgraded, you can run:

apt-mark hold docker.io

his will prevent docker from being upgraded until you remove it from the hold list. To remove it from the hold list, you can use the apt-mark unhold command. For example:

apt-mark unhold docker.io

I hope this quick tip helps you with downgrading the apt packages when the need arises. Let me know if you have questions or suggestions.

Good Luck!

Leave a Comment

Share this Doc

How to downgrade a Package via apt-get

Or copy link

CONTENTS