Home » Questions » Computers [ Ask a new question ]

How to tell from what Ubuntu or Debian repository a package comes?

How to tell from what Ubuntu or Debian repository a package comes?

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/).

Asked by: Guest | Views: 93
Total answers/comments: 3
Guest [Entry]

"I run apt-cache policy <package name>:

$ apt-cache policy wajig
wajig:
Installed: 2.1
Candidate: 2.1
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)
One that is available from a local repository (file:/home/wena/.repo_bin/)
One that is available from a remote repository (ftp://ftp.is.co.za/debian), which also happens to have the same version (2.0.47) as the one in a local 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"
Guest [Entry]

"I wonder why no one mentioned aptitude. I use it all the time.
Aptitude is:

Shipped by default with many Debian-based distributions. Can be installed to other (such as Ubuntu) via sudo apt install aptitude.

Does not require administrative privileges (at least for the command below).

Does have a nice ncurses GUI (but most of the time used without it).

Provides a really pretty output. To show versions of packages, use aptitude versions command:
me@wheezy:~$ aptitude versions kde-standard
Package kde-standard:
i A 5:77+deb7u1 stable 500
p A 5:84 testing,unstable 130

Does NOT have Super Cow Powers.

The letter in front of each string indicates the package's status, i is installed and p is purged (or never installed), stable, testing and unstable are repository definitions, the number in the end is a pin priority.
One caveat regarding recent versions of aptitude worth a mentioning here: by default it shows all the packages, which include the name you search, so use a regex magic a little to search by the strict name, for example aptitude versions ^kde-workspace$."
Guest [Entry]

"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."