How can I know which updates come from which of the defined repos?

If I run the following on my Ubuntu18 (Ubuntu 18.04.4 LTS) test machine I see the following repos defined:

root@ubuntu18:/root# cat /etc/apt/sources.list | grep -v '#'
deb http://archive.ubuntu.com/ubuntu bionic main restricted
deb http://archive.ubuntu.com/ubuntu bionic-updates main restricted
deb http://archive.ubuntu.com/ubuntu bionic universe
deb http://archive.ubuntu.com/ubuntu bionic-updates universe
deb http://archive.ubuntu.com/ubuntu bionic multiverse
deb http://archive.ubuntu.com/ubuntu bionic-updates multiverse
deb http://archive.ubuntu.com/ubuntu bionic-backports main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu bionic-security main restricted
deb http://archive.ubuntu.com/ubuntu bionic-security universe
deb http://archive.ubuntu.com/ubuntu bionic-security multiverse

Running apt list –upgradable shows I have updates available however I would like to know which repo each of the updates are coming from or alternatively run a command to iterate through each defined repo and show me the respective update list.

Asked By: dross

||

As you already know, you can list upgradable packages with:

apt list --upgradable

… for example on my system that shows:

$ apt list --upgradable
Listing... Done
gdb/lunar 13.1-2ubuntu2 amd64 [upgradable from: 12.1-0ubuntu1~22.04]
google-chrome-stable/stable 119.0.6045.105-1 amd64 [upgradable from: 118.0.5993.117-1]
libpeas-1.0-0/lunar 1.36.0-1 amd64 [upgradable from: 1.32.0-1]
libpython3-dev/lunar 3.11.2-1 amd64 [upgradable from: 3.10.6-1~22.04]
libsndfile1/lunar-updates,lunar-security 1.2.0-1ubuntu0.1 amd64 [upgradable from: 1.2.0-1]

More information about individual packages including their repository can be viewed with:

apt policy package-name

… like:

$ apt policy gdb
gdb:
  Installed: 12.1-0ubuntu1~22.04
  Candidate: 13.1-2ubuntu2
  Version table:
     13.1-2ubuntu2 500
        500 http://archive.ubuntu.com/ubuntu lunar/main amd64 Packages
 *** 12.1-0ubuntu1~22.04 100
        100 /var/lib/dpkg/status

So, you can trim the output of the former and pass it to the latter to automate that with something like:

apt list --upgradable |& awk -F'/' '///{print $1}' | xargs apt policy

… and again, on my system, it looks like this:

$ apt list --upgradable |& awk -F'/' '///{print $1}' | xargs apt policy
gdb:
  Installed: 12.1-0ubuntu1~22.04
  Candidate: 13.1-2ubuntu2
  Version table:
     13.1-2ubuntu2 500
        500 http://archive.ubuntu.com/ubuntu lunar/main amd64 Packages
 *** 12.1-0ubuntu1~22.04 100
        100 /var/lib/dpkg/status
google-chrome-stable:
  Installed: 118.0.5993.117-1
  Candidate: 119.0.6045.105-1
  Version table:
     119.0.6045.105-1 500
        500 https://dl.google.com/linux/chrome/deb stable/main amd64 Packages
 *** 118.0.5993.117-1 100
        100 /var/lib/dpkg/status
libpeas-1.0-0:
  Installed: 1.32.0-1
  Candidate: 1.36.0-1
  Version table:
     1.36.0-1 500
        500 http://archive.ubuntu.com/ubuntu lunar/main amd64 Packages
 *** 1.32.0-1 100
        100 /var/lib/dpkg/status
libpython3-dev:
  Installed: 3.10.6-1~22.04
  Candidate: 3.11.2-1
  Version table:
     3.11.2-1 500
        500 http://archive.ubuntu.com/ubuntu lunar/main amd64 Packages
 *** 3.10.6-1~22.04 100
        100 /var/lib/dpkg/status
libsndfile1:
  Installed: 1.2.0-1
  Candidate: 1.2.0-1ubuntu0.1
  Version table:
     1.2.0-1ubuntu0.1 500
        500 http://archive.ubuntu.com/ubuntu lunar-updates/main amd64 Packages
        500 http://archive.ubuntu.com/ubuntu lunar-security/main amd64 Packages
 *** 1.2.0-1 500
        500 http://archive.ubuntu.com/ubuntu lunar/main amd64 Packages
        100 /var/lib/dpkg/status
Answered By: Raffa
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.