Is there a way to list all non-free and contrib software installed in Debian via apt?

/etc/apt/sources.list is as follows

deb http://ftp.us.debian.org/debian/ wheezy main non-free contrib
deb-src http://ftp.us.debian.org/debian/ wheezy main non-free contrib

deb http://security.debian.org/ wheezy/updates main non-free contrib
deb-src http://security.debian.org/ wheezy/updates main non-free contrib

# wheezy-updates, previously known as 'volatile'
deb http://ftp.us.debian.org/debian/ wheezy-updates main
deb-src http://ftp.us.debian.org/debian/ wheezy-updates main

I added non-free and contrib years ago because I needed a non-free driver for my video-card, which has now been replaced with a new one that doesn't require a non-free driver. I'd like to get rid of the non-free stuff, but I'm afraid I might have installed other non-free software over the years which I cannot afford to uninstall.


6 Answers 6

  • dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-free
  • aptitude search '~i ?section(non-free)'

Section will be non-free/... for everything from the non-free path.

[Note] for gcc docs...

 This documentation is licensed under the terms of the GNU Free
 Documentation License, and contains invariant sections, so it can't be
 part of Debian main.

(I wondered about that too, but didn't bother checking until it was mentioned.)

  • Both yielded different results (pastebin.com/rAhYHTk8). The NVIDIA stuff is the driver, so dpkg seems right! Upvoted. I just wonder what gcc-doc is doing there.
    – Alex
    Commented Jan 27, 2014 at 10:13
  • The NVIDIA stuff was already removed, apt probably listed it because it kept the .deb or something. I just remembered one thing I have from non-free which wasn't listed: dpkg -l | grep -i nonfree results in flashplugin-nonfree. I wonder why that wasn't listed by aptitude and if it's actually listing everything from non-free.
    – Alex
    Commented Jan 27, 2014 at 10:22
  • 2
    Because it's in contrib :: debian/pool/contrib/f/flashplugin-nonfree (Section: contrib/web)
    – Ricky
    Commented Jan 27, 2014 at 10:37
  • 3
    A one-liner for both sections is dpkg-query -W -f='${Section}\t${Package}\n' | sort | egrep ^contrib\|^non-free
    – GKFX
    Commented Jul 12, 2015 at 10:02
  • Regarding dpkg-query -W -f='${Section}\t${Package}\n': Section does not display the components. (At least, it does not for me on Ubuntu 18.04.) An example component might be main, contrib, or non-free. Whereas sections are things like: admin, gnome, utils, or x11.
    – mpb
    Commented Aug 23, 2018 at 16:20

There is a program called VRMS (a virtual Richard M. Stallman) which will report all the non-free software on your system in a short summary. Its in the repo's and you can install it via apt ;-)

  • 3
    It's worth mentioning vrms adds itself to /etc/cron.monthly. I was pleasantly surprised when I got a mail from virtual Stallman a month after the install.
    – Alex
    Commented May 7, 2014 at 18:49

I had a similar 'urge' a few years ago and could not determine that the orginal package information is kept on the system after downloading the package. I don't think this information is available to dpkg.

So what I ended up was setup a clean virtual machine, setup the appropriate /etc/apt/sources.list and installed the whole list generated by:

dpkg --get-selections | fgrep -v deinstall | cut -s -f 1

the packages that would not install (I only did download to save some time with apt-get -d).

You might be able to do a similar thing using apt-get --root-directory=some_dir after temporarily changing your sources.list, but I would not sure if that uses your current install database and just moves the package there. A VM for this kind of experimenting is much safer. I normally have a clean basic install of my current Linux as VM, so I only have to clone that (not that installing Linux on a VM takes that long).

  • Nice "solution". I currently don't have the disk space for it, but I imagine apt will first display the packages that weren't found (hence are non-free), correct?
    – Alex
    Commented Jan 27, 2014 at 10:14
  • @Alex Yes that is correct. That is kind of missing from the answer. But Ricky's approach is better unless the unlikely happened and a package actually moved over time from one repo to another (and you are not up-to-date or the package did not change version number).
    – Timo
    Commented Jan 27, 2014 at 12:34

Visit Ask Ubuntu. Here the command line:

FILTER=non-free TMP_DIR=$(mktemp -d) && {
  dpkg -l | grep ^ii | cut -f 3 -d' ' | cut -f 1 -d : | sort | uniq > ${TMP_DIR}/pkg_installed.list
  cat /var/lib/apt/lists/*_${FILTER}_*Packages | grep "^Package:"  | sort | uniq | cut -d' ' -f2 > ${TMP_DIR}/pkg_filtered.list
  comm -12 ${TMP_DIR}/pkg_installed.list ${TMP_DIR}/pkg_filtered.list

id like to answer for the opposite task. suppose we have a package and we want to know from which repo it can be installed.

for example "gnumeric"

# export name="gnumeric" && grep "$name" -Ri /var/lib/apt/lists | grep "Package: $name$" | grep binary | grep "ubuntu.com"
/var/lib/apt/lists/ftp.ubuntu.com_ubuntu_dists_bionic_universe_binary-amd64_Packages:Package: gnumeric

# grep "ubuntu.com" -Ri /etc/apt | grep "bionic universe"
/etc/apt/sources.list:deb  [ arch=amd64 ] http://us.archive.ubuntu.com/ubuntu/ bionic universe

that is the answer:

deb  [ arch=amd64 ] http://us.archive.ubuntu.com/ubuntu/ bionic universe

As of APT 2.0 (Debian 10 Buster, Ubuntu 20.04 Focal), you can use the same apt-patterns(5) syntax with APT and without aptitude:

# Debian
apt list '?installed ?section(non-free)'
apt list '~i ~snon-free'

# Ubuntu
apt list '?installed ?section(multiverse)'
apt list '~i ~smultiverse'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .