0

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)?

Avinash Raj
  • 78,556

2 Answers2

1

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
Radu Rădeanu
  • 169,590
  • 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 01 '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 02 '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 02 '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 02 '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 02 '14 at 14:15
  • @JasonConti It's impossible to produce incorrect output. Check the logic from the answer. And if you have doubts about one package if is installed or not you can use apt-cache policy <package name> command to check. If you think that there are to many, that is normal too, because almost everyone package has past by its first version. – Radu Rădeanu Apr 02 '14 at 14:21
  • This is the output when I copy and paste your last command and run it on my saucy system: http://paste.ubuntu.com/7194901/ That lists 230 unique packages. When I run those through apt-cache policy I get: http://paste.ubuntu.com/7194902/ So we can see that of the 230 packages, only 11 are actually installed, and only the two libjpeg-turbo packages actually have candidates for downgrading. Here's the output of my script for comparison: http://paste.ubuntu.com/7194914/ – Jason Conti Apr 02 '14 at 16:13
  • @JasonConti Ok. Now, for example, what is the output of apt-cache policy acl? – Radu Rădeanu Apr 02 '14 at 16:22
  • http://paste.ubuntu.com/7194991/ Yes the amd64 version is installed, but there is only one version available in the repositories. – Jason Conti Apr 02 '14 at 16:35
  • @JasonConti No, is not the only one. According with http://paste.ubuntu.com/7194901/ there is another one (acl:i386 2.2.52-1), your currently version of acl:2.2.52-1 can be downgraded at acl:i386 2.2.52-1. Case closed! – Radu Rădeanu Apr 02 '14 at 16:44
  • Alright, I am done arguing now. Downgrading an amd64 package to an i386 package is just ridiculous, and obviously not in the spirit of the question. Read the first answer to http://askubuntu.com/questions/138284/how-to-downgrade-a-package-via-apt-get which is linked in the question. – Jason Conti Apr 02 '14 at 16:48
  • @JasonConti Yes, I must to admit that is not the best way to say that, but is not an upgrade also... And you can install different architecture packages in your system. If you want to remove i386 packages from that list, you can use apt-cache showpkg $i | sed "0,/Reverse Provides:/d" | grep -v i386, but in this way you can lose some downgrades for the 32-bit packages installed in your system. – Radu Rădeanu Apr 02 '14 at 17:24
-1

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:
      result.append(version.version)
  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.

Jason Conti
  • 2,371
  • 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 02 '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 02 '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 02 '14 at 17:51