This question is just an opposite of How do you see what packages are available for update question.

I want to check the answers in this question, is that the given answers really downgrade an installed package.It's so hard to run apt-cache policy package command on each and every installed package and to manually check for the available low versions in the repository.

So, is there any command to list all the installed packages which has a lower version available in the repositories(Packages which can be downgraded)?

  • @DKBose Now it looks like a clear one. – Avinash Raj Apr 1 '14 at 3:08

You can check if a specific package has an possible candidate for downgrade using:

apt-cache showpkg package_name | sed "0,/Reverse Provides:/d"

Now, according with this Q&A you can use:

dpkg --get-selections | grep -v deinstall

to list all your installed packages which are "available for downgrade" af follow:

for i in $(dpkg --get-selections | grep -v deinstall | cut -f1); do apt-cache showpkg $i | sed "0,/Reverse Provides:/d"; done
| improve this answer | |
  • Are you sure this works correctly? Every package I look at in the output when I run it isn't actually installed... – Jason Conti Apr 1 '14 at 20:17
  • @JasonConti Yes, I'm sure. If you have doubts, see How can I check if a package is installed?. – Radu Rădeanu Apr 2 '14 at 11:15
  • Have you actually run it? Try it and compare the output with apt-cache policy. On a nearly fresh trusty system it returns many packages when it should return zero. On my saucy system it returns many packages either not installed or with only one version available. Compare with the output of my script below. – Jason Conti Apr 2 '14 at 13:58
  • @JasonConti Of course I run it. And I can't compare with your script which will work only for a small number of packages, not all installed packages. – Radu Rădeanu Apr 2 '14 at 14:04
  • Mine should loop through every package in the apt database but I will more than happily check it more thoroughly later. In any case, on my amd64 systems running you commands produces incorrect output. If it works for you, fine. – Jason Conti Apr 2 '14 at 14:15

Not sure about a command, but here is a bit of python:

from __future__ import print_function

import apt

def downgrade_versions(package):
  if package.versions is None or not package.is_installed:
    return []
  result = []
  for version in package.versions:
    if version < package.installed:
  return result

with apt.Cache() as cache:
  for package in cache:
    versions = downgrade_versions(package)
    if len(versions) > 0:
      print(package.fullname, package.installed.version, versions)

Prints the package name, the installed version, and a list of available versions less than the installed version.

For an individual package you can use apt-cache policy package. It shows the installed version and the available versions.

| improve this answer | |
  • In my case, this is the output of your script, but I am sure that there should be more packaged in that list... – Radu Rădeanu Apr 2 '14 at 17:35
  • @RaduRădeanu Looks like you are on 14.04 from the package versions. I don't actually get any output on 14.04 because we only have the -release repository during testing (there is also -proposed, but it isn't a good idea to run that on testing versions). The output you do get is from the xorg-edgers ppa, so that makes sense, because you can downgrade back to the -release version. On saucy I get many more packages because we also have the -updates, -security and -backports repositories that we don't yet have on the testing version. – Jason Conti Apr 2 '14 at 17:50
  • @RaduRădeanu strange that they are old saucy versions from edgers, but they might be leftover packages if you did an upgrade from 13.10 to 14.04 and removed the ppa but didn't purge the packages first. – Jason Conti Apr 2 '14 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.