Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

On a Debian-based system, including Ubuntu, how can one tell which repository a package will be downloaded from, without actually beginning the download? aptitude show and apt-cache info will show the section (e.g., metapackage, base, graphics), but not the repository to which a package belongs (e.g., http://ppa.launchpad.net/mactel-support/ppa/ubuntu or http://us.archive.ubuntu.com/ubuntu/).

When installing the package, the actual repository appears during the download (it is printed out in the "downloading from ..." output from apt and similar programs), but how can one obtain information on the repository containing the package (or a specific version of a package) without downloading and installing it first?

Additionally, how can one determine the source repository for a package that is already installed?

share|improve this question
1  
i find this one of the deficiencies of Apt; it's just not easy to tell from which repository provides a certain package within the package installer tools. –  quack quixote Feb 9 '10 at 19:52
add comment

6 Answers

up vote 92 down vote accepted

I run apt-cache policy <package name>:

$ apt-cache policy wajig
wajig:
  Installed: 2.01
  Candidate: 2.01
  Version table:
 *** 2.1 0
        100 /var/lib/dpkg/status
     2.0.47 0
        500 file:/home/wena/.repo_bin/ squeeze/main i386 Packages
        500 ftp://ftp.is.co.za/debian/ squeeze/main i386 Packages

That means that there are three wajig packages, one that is installed (/var/lib/dpkg/status), and two others (which are the same version). One of these two is in a local repository and the other is available from a remote repository.

Additionally, apt-cache madison <package name> will display similar information in a tabular format.

 wajig |        2.2 | mirror://mirrors.ubuntu.com/mirrors.txt/ precise/universe amd64 Packages
 wajig |        2.2 | mirror://mirrors.ubuntu.com/mirrors.txt/ precise/universe Sources
share|improve this answer
3  
+1 This is by far the best answer. Almost want to downvote the others. –  Mikel Jan 23 '11 at 2:10
    
But it doesn't show where the installed package came from, does it? –  Adobe Apr 27 '12 at 11:16
    
@Adobe In my case, the 2.1 version isn't available from any repository. It's locally-built. –  Tshepang Apr 29 '12 at 9:26
    
What is sign of installed package? *** or /var/lib/dpkg/status ? –  SuB Sep 19 '13 at 17:39
    
Maybe both? Not sure. –  Tshepang Sep 19 '13 at 20:24
add comment

Aha! Apparently, the proper apt command is not apt-cache info, but instead, apt-cache showpkg.

$ apt-cache showpkg linux-generic
Package: linux-generic
Versions: 
2.6.31.19.32 (/var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_karmic-updates_main_binary-amd64_Packages) (/var/lib/apt/lists/security.ubuntu.com_ubuntu_dists_karmic-security_main_binary-amd64_Packages) (/var/lib/dpkg/status)
 Description Language: 
                 File: /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_karmic-updates_main_binary-amd64_Packages
                  MD5: 5d722da329763b9342d322f5a140005c

2.6.31.14.27 (/var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_karmic_main_binary-amd64_Packages)
 Description Language: 
                 File: /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_karmic_main_binary-amd64_Packages
                  MD5: 5d722da329763b9342d322f5a140005c


Reverse Depends: 
Dependencies: 
2.6.31.19.32 - linux-image-generic (5 2.6.31.19.32) 
2.6.31.14.27 - linux-image-generic (5 2.6.31.14.27) 
Provides: 
2.6.31.19.32 - 
2.6.31.14.27 - 
Reverse Provides: 

The File: line provides the repository information after the /var/lib/apt/lists/.

There is a bug report that aptitude cannot display the source repository, but it seems at present the feature is still on the wish list.

share|improve this answer
add comment

This works for me (shows where the 2vcard package is):

$ grep 2vcard /var/lib/apt/lists/* | grep "Filename:"

/var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_karmic_universe_binary-i386_Packages:Filename: pool/universe/2/2vcard/2vcard_0.5-3_all.deb

You can apply additional filtering to check versions, etc., if multiple versions are available.

share|improve this answer
    
Pragmatic. I'm surprised this information is not accessible through any of the front ends to dpkg, though. –  gotgenes Feb 10 '10 at 0:27
    
@got It is available: superuser.com/questions/106794/… –  Tshepang Jan 23 '11 at 7:41
add comment

Sadly, this information is not recorded during package installation. You can make a decent guess if the repository is still in the source list and the repository still has the package:

grep -l PKG /var/lib/apt/lists/*

apt-cache showpkg is showing data from the repository database (not what is installed) so it's another form of the same information from the grep.

Even synaptic cannot tell (in the Origin screen) if you disable the repository and update.

share|improve this answer
add comment

Or, inspired by Sunny you can try:

# list installed restricted packages
for i in `dpkg --get-selections | awk '{ print $1 }'`; do egrep -lRI "^Filename: .*/${i}_[^/]+.deb" /var/lib/apt/lists/ | grep -q 'restricted' && echo $i; done

# list installed multiverse packages
for i in `dpkg --get-selections | awk '{ print $1 }'`; do egrep -lRI "^Filename: .*/${i}_[^/]+.deb" /var/lib/apt/lists/ | grep -q 'multiverse' && echo $i; done

ps. not 100% accurate.

share|improve this answer
add comment

I use a script i wrote for that purpose: https://github.com/fab1an/unix-admin-tools/blob/master/dpkg-origins

It uses dpkg-query and the /var/lib/apt/lists/* information to produce output like this:

$> dpkg-origins.sh *apt*
Filter: *apt*

at.archive.ubuntu.com_ubuntu_dists_oneiric-updates_main:

     apt                                     0.8.16~exp5ubuntu13.2                   APT's commandline package manager
     apt-transport-https                     0.8.16~exp5ubuntu13.2                   https download transport for APT
     apt-utils                               0.8.16~exp5ubuntu13.2                   APT utility programs
     libapt-inst1.3                          0.8.16~exp5ubuntu13.2                   APT's deb package format runtime library
     libapt-pkg4.11                          0.8.16~exp5ubuntu13.2                   APT's package managment runtime library

at.archive.ubuntu.com_ubuntu_dists_oneiric_main:

     apt-xapian-index                        0.44ubuntu4                             maintenance and search tools for a Xapian index of Debian packages
     aptitude                                0.6.4-1ubuntu2                          terminal-based package manager (terminal interface only)
     laptop-detect                           0.13.7ubuntu2                           attempt to detect a laptop
     libapt-pkg-perl                         0.1.24build3                            Perl interface to libapt-pkg
     python-apt                              0.8.0ubuntu9                            Python interface to libapt-pkg
     python-apt-common                       0.8.0ubuntu9                            Python interface to libapt-pkg (locales)

at.archive.ubuntu.com_ubuntu_dists_oneiric_universe:

     apt-file                                2.5.0ubuntu1                            search for files within Debian packages (command-line interface)

security.ubuntu.com_ubuntu_dists_oneiric-security_main:

     apt                                     0.8.16~exp5ubuntu13.2                   APT's commandline package manager
     apt-transport-https                     0.8.16~exp5ubuntu13.2                   https download transport for APT
     apt-utils                               0.8.16~exp5ubuntu13.2                   APT utility programs
     libapt-inst1.3                          0.8.16~exp5ubuntu13.2                   APT's deb package format runtime library
     libapt-pkg4.11                          0.8.16~exp5ubuntu13.2                   APT's package managment runtime library

not found in any repository:

     ....
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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