9

On an Ubuntu 10.04 LTS server, I want to list installed packages and see what repository they come from.

It’s easy to list installed packages, but it does not include the name of the repository (such as “main” or “universe”). And this information isn’t in /var/lib/dpkg/status, so dpkg-query doesn’t show it either.

I want to get a list of “unsupported” software—that is, software that doesn’t come from the “main” repository, and for which Ubuntu does not guarantee security updates.

Note: This is a server. It does not have X, GNOME or KDE installed.

Nate
  • 2,316
  • 4
  • 21
  • 24

4 Answers4

14

Okay, I figured out how to do this:

aptitude search "~i" -F "%s# %p"

Which of course can easily be grepped to find items from the “universe” repository:

aptitude search "~i" -F "%s# %p" | grep universe
Ivan Kozik
  • 123
  • 5
Nate
  • 2,316
  • 4
  • 21
  • 24
  • 2
    +1. I was getting there, but I am surprised this isn't better documented either in Ubuntu documentation or Debian's website. It is something I do all the time in Synaptic, but I have never yet needed it from CLI. – Richard Holloway May 04 '10 at 21:11
  • 1
    `aptitude search -F "%s# %p" "~i ?section(universe)"` – jarno Apr 11 '19 at 11:43
1

You can provide a custom format for the output of the dpkg command (using the -f option). Try something like this, using the Origin variable:

dpkg-query -f='${Package} ${Version}\t${Origin}\n' --get-selections

There's more info on the formatting argument on this page: http://www.tin.org/bin/man.cgi?section=1&topic=dpkg-query

The default format string is "${Package}\t${Version}\n". Actu- ally, all other fields found in the status file (i.e. user defined fields) can be requested, too. They will be printed as- is, though, no conversion nor error checking is done on them. To get the name of the dpkg maintainer and the installed ver- sion, you could run:

dpkg-query -W -f='${Package} ${Version}\t${Maintainer}\n' dpkg

John Rabotnik
  • 439
  • 2
  • 5
  • 3
    Unfortunately neither `${Origin}` nor `${Source}` give any output. Example query: `dpkg-query -W -f='${Package} ${Version}\t${Origin}\n' 'apache2*'`. If `dpkg-query` is getting its data from `/var/lib/dpkg/status` then it won’t have the information because that file does not identify the origin repository. – Nate May 04 '10 at 20:06
  • 3
    This does not work. `--get-selections` is not a valid argument to `dpkg-query`. – Reinderien Nov 25 '18 at 00:35
1

I tried aptitude search ~i -F "%s# %p"

in ubuntu 12.04 and 14.04 but it didn't show repositories.

So I wrote this small script:

# more origins.sh
#!/bin/bash
for i in $(dpkg -l |grep ^ii |awk -F' ' '{print $2}'); do
  apt-cache showpkg "$i"|head -3|grep -v '^Versions'|cut -d'(' -f2|cut -d')' -f1|sed -e 's/^Package: //;' | paste -d '\t' - -
done

Then

bash origins.sh|grep universe
k-h
  • 139
  • 4
  • The version extracted from `showpkg` output isn't necessarily the installed version, so this might work for you, but if a package is available from more than one repository in `sources.list` (say, if you have backports enabled), it will not show you from which repository the package has been installed. – Aryeh Leib Taurog Oct 12 '15 at 08:53
  • this is really cool. Actually it is really helpful and important because universe is not updated 5 years in LTS unlike main :( More info: http://www.wilderssecurity.com/threads/ubuntu-lts-many-vulnerabilities-despite-long-term-support.385386/ – therealmarv Apr 25 '16 at 08:28
0

This is not exactly an answer but might be used to help. A colleague showed me this the other day. You can find out where a package is from using this command:

apt-cache policy <package-name>

For example:

 apt-cache policy xterm  
 xterm:  
 Installed: 271-1ubuntu2.1    
 Candidate: 271-1ubuntu2.1  
 Version table:    *** 271-1ubuntu2.1 0  
         500 http://mirror.internode.on.net/pub/ubuntu/ubuntu/ precise-updates/main amd64 Packages  
         100 /var/lib/dpkg/status  
      271-1ubuntu2 0  
         500 http://mirror.internode.on.net/pub/ubuntu/ubuntu/ precise/main amd64 Packages
chicks
  • 3,639
  • 10
  • 26
  • 36
k-h
  • 139
  • 4