There are multiple ways of finding out to which package a particular file belongs to, on Ubuntu, Debian or Linux Mint. This article presents two ways of achieving this, both from the command line.
1. Using apt-file to find the package that provides a file (for repository packages, either installed or not installed)
apt-file indexes the contents of all packages available in your repositories, and allows you to search for files in all these packages.
That means you can use apt-file to search for files inside DEB packages that are installed on your system, as well as packages that are not installed on your Debian (and Debian-based Linux distributions, like Ubuntu) machine, but are available to install from the repositories. This is useful in case you want to find what package contains a file that you need to compile some program, etc.
apt-file cannot find the package that provides a file in case you downloaded a DEB package and installed it, without using a repository. The package needs to be available in the repositories for apt-file to be able to find it.
apt-file may not be installed on your system. To install it in Debian, Ubuntu, Linux Mint and other Debian-based or Ubuntu-based Linux distributions, use this command:
sudo apt install apt-file
This tool find the files belonging to a package by using a database, which needs to be updated in order to be able to use it. To update the apt-file database, use:
sudo apt-file update
Now you can use apt-file to find the DEB package that provides a file, be it a package you've installed from the repositories, or a package available in the repositories, but not installed on your Debian / Ubuntu / Linux Mint system. To do this, run:
apt-file search filename
filename with the name of the file you want to find.
This command will list all occurrences of
filename found in various packages. If you know the exact file path and filename, you can get the search results to only list the package that includes that exact file, like this:
apt-file search /path/to/filename
For example, running only
apt-file search cairo.h will list a large list search results:
$ apt-file search cairo.h fltk1.3-doc: /usr/share/doc/fltk1.3-doc/HTML/group__group__cairo.html ggobi: /usr/include/ggobi/ggobi-renderer-cairo.h glabels-dev: /usr/include/libglbarcode-3.0/libglbarcode/lgl-barcode-render-to-cairo.h glabels-dev: /usr/share/gtk-doc/html/libglbarcode-3.0/libglbarcode-3.0-lgl-barcode-render-to-cairo.html gstreamer1.0-plugins-good-doc: /usr/share/gtk-doc/html/gst-plugins-good-plugins-1.0/gst-plugins-good-plugins-plugin-cairo.html guile-cairo-dev: /usr/include/guile-cairo/guile-cairo.h guitarix-doc: /usr/share/doc/guitarix-doc/namespacegx__cairo.html ipe: /usr/share/ipe/7.2.7/doc/group__cairo.html libcairo-ocaml-dev: /usr/share/doc/libcairo-ocaml-dev/html/Pango_cairo.html libcairo-ocaml-dev: /usr/share/doc/libcairo-ocaml-dev/html/type_Pango_cairo.html libcairo2-dev: /usr/include/cairo/cairo.h ...
However, if you know the file path, e.g. you want to find out to which package the file
/usr/include/cairo/cairo.h belongs to, run:
apt-file search /usr/include/cairo/cairo.h
This only lists the package that contains this file:
$ apt-file search /usr/include/cairo/cairo.h libcairo2-dev: /usr/include/cairo/cairo.h
In this example, the package that includes the file I searched for (
apt-file may also be used to list all the files included in a package (
apt-file list packagename), perform regex search, and more. Consult its man page (
man apt-file) and help for more information (
2. Using dpkg to find the package that provides a file (only for installed DEB packages - from any source)
dpkg can also be used to find out to which package a file belongs to. It can be faster to use than apt-file, because you don't need to install anything, and there's no database to update.
However, dpkg can only search for files belonging to installed packages, so if you're searching for a file in a package that's not installed on your system, use apt-file. On the other hand, dpkg can be used to find files belonging to packages that were installed without using a repository, a feature that's not available for apt-file.
To use dpkg to find the installed DEB package that provides a file, run it with the
--search) flag, followed by the filename (or pattern) you want to see to which package it belongs, like this:
dpkg -S filename
For example, to find out to which package the
cairo.h file belongs to, use
dpkg -S cairo.h:
$ dpkg -S cairo.h libgtk2.0-dev:amd64: /usr/include/gtk-2.0/gdk/gdkcairo.h libcairo2-dev:amd64: /usr/include/cairo/cairo.h libpango1.0-dev: /usr/include/pango-1.0/pango/pangocairo.h libgtk-3-dev:amd64: /usr/include/gtk-3.0/gdk/gdkcairo.h
Just like for apt-file, this may show multiple packages that have files containing the filename you're looking for. You can enter the full path of the file to get only the package that contains that specific file. Example:
$ dpkg -S /usr/include/cairo/cairo.h libcairo2-dev:amd64: /usr/include/cairo/cairo.h
In this example, the Debian package that includes the file I searched for (
Other notable ways of finding the package a file belongs to is using the online search provided by Ubuntu and Debian:
- Ubuntu: https://packages.ubuntu.com/ - scroll down to
Search the contents o packagesand enter the filename you're looking for, as well as the distribution (Ubuntu version) and architecture.
- Debian: https://www.debian.org/distrib/packages#search_contents - the search is similar to the one available for Ubuntu, so enter the filename you want to find, the distribution and architecture.
For both, you'll also find options to find the packages that contain files named exactly like your input keyword, packages ending with the keyword, or packages that contains files whose names contain the keyword.
The Linux Mint package search website doesn't include an option to search for files inside packages, but you can use the Ubuntu or Debian online package search for packages that Linux Mint imports from Debian / Ubuntu.