How to list available backport upgrades

I have just followed Ubuntu Backports to activate manual backports and I have a couple of questions. How can I, in the command line (e.g. apt-cacher or aptitude):

  1. list installed packages that have available backport upgrades? (Before, I used apt-show-versions -u for upgradeable packages)
  2. list all available backport packages (installed or not)?

  1. list installed packages that have available backport upgrades

    aptitude search '?and(~i, ~Araring-backports)'
    
  2. list all available backport packages (installed or not)

    aptitude search '~Abackports ?not(~S ~i ~Abackports)'
    

This information is available in Synaptic, which is not installed by default but can be obtained with,

sudo apt-get install synaptic

Selecting Origin in the left sidebar will allow packages to be browsed by where they come from, such as raring-backports/universe, as well as locally installed packages.

If you are instead interested in a command line solution, I hacked together a quick-and-dirty python script to list packages in backports, though unfortunately it is rather slow.

from __future__ import print_function

import apt

def backport_version(package):
  if package.versions is None:
    return False
  for version in package.versions:
    for origin in version.origins:
      if origin.archive.endswith("backports"):
        return version.version
  return None

with apt.Cache() as cache:
  for package in cache:
    version = backport_version(package)
    if version is not None:
      print(package.fullname, version)
      if package.is_installed:
        print("    Installed:", package.installed.version)

It lists all available backport packages, and the installed version if it is installed.


EDIT: After some experimentation, I found a solution that works perfectly for me! It lists only the packages that have a newer version in the -backports repository, and nothing more (the other solutions listed additional packages.

To list available backports updates, run this command:

aptitude search -t $(lsb_release -sc)-backports '~U ~Abackports'

If you want the list to also display the current and newer version, run this command instead:

aptitude search -t $(lsb_release -sc)-backports -F '%p %v -> %V' '~U ~Abackports'

This will display something like this:

nvidia-settings               331.20-0ubuntu -> 346.59-0ubuntu
screen                        4.1.0~20120320 -> 4.2.1-2~ubuntu
yelp-xsl                      3.10.1-1       -> 3.12.0-1~ubunt

If you don't want to memorize this command, add this to your ~/.bashrc:

alias apt-list-backports="aptitude search -t $(lsb_release -sc)-backports -F '%p %v -> %V' '~U ~Abackports'"

Now you only have to write apt-list-backports!


Original answer

Just found another way:

apt-get upgrade -s -t $(lsb_release -sc)-backports

This will simulate an upgrade and list what packages would be upgraded. But the upgrades to backports are also included (I think normal upgrades are shown too).

You can also add the option -V to show the versions that the packages would be upgraded to.


To view the changelog of a package in the backports, use:

apt-get changelog -t $(lsb_release -sc)-backports PACKAGE_NAME