How to list configured APT repositories

List configured APT data sources for binary packages using apt-cache utility.

Notice that this solution will not list repositories for source packages.

First approach

The simplest approach is to use apt-cache utility to print package repositories.

$ apt-cache policy | awk '/http/ { printf "%s %s\n",$2,$3 }' | sort | uniq wheezy-backports/contrib wheezy-backports/main wheezy-backports/non-free wheezy/contrib wheezy/main wheezy/non-free wheezy/updates/contrib wheezy/updates/main wheezy/updates/non-free

Second approach

Modify it a bit to pretty print the parsed data.

$ printf "%-60s %s\n" "URI" "Suite and section"; apt-cache policy | awk '/http/ { printf "%-60s %s\n",$2,$3 }' | sort | uniq | sed -e "s|\(.*\)\/|\1 |"
URI                                                          Suite and section                             wheezy-backports contrib                             wheezy-backports main                             wheezy-backports non-free                             wheezy contrib                             wheezy main                             wheezy non-free                                  wheezy/updates contrib                                  wheezy/updates main                                  wheezy/updates non-free

You can quickly extend it to print out the priorities of each source.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland