The Debian distribution has the Debian Alternatives System. From the Wiki:

The Debian alternatives system creates a way for several programs that fulfill the same or similar functions to be listed as alternative implementations that are installed simultaneously but with one particular implementation designated as the default. For example many systems have several text editors installed at the same time. The vi program is a classic example of an editor that has many implementations such as nvi, elvis, vim, etc. but which one should be designated as the default?

In general, there are multiple packages in Debian that provide a particular alternative. How does one obtain a complete list of all such packages that exist in the Debian repositories? Let us use the vi alternative as an example.

NOTE: Doing such a query against the list of installed packages is easy, but that is not what this question asks.

6 Answers 6


Virtual packages and the Debian alternatives system (which is where binaries come into play) are related but not the same. For virtual packages, you can use apt-cache to find which (real) packages "provide" it:

$ apt-cache showpkg awk
Package: awk

Reverse Depends: 
Reverse Provides: 
mawk:i386 1.3.3-17ubuntu2
gawk:i386 1:4.0.1+dfsg-2.1ubuntu2
original-awk 2012-12-20-1
mawk 1.3.3-17ubuntu2
gawk 1:4.0.1+dfsg-2.1ubuntu2

For display managers, the virtual package is x-display-manager:

$ apt-cache showpkg x-display-manager
Package: x-display-manager

Reverse Depends: 
Reverse Provides: 
lightdm 1.10.6-0ubuntu1
kdm 4:4.11.11-0ubuntu0.2
xdm 1:1.1.11-1ubuntu1
wdm 1.28-16
slim 1.3.4-2.1
lxdm 0.4.1-0ubuntu6
kdm 4:4.11.8-0ubuntu6
lightdm 1.10.0-0ubuntu3

The alternatives system is handled by calls to update-alternatives in maintainer scripts as Braiam's answer shows, and the rest of the packaging system is blissfully unaware of these. The Provides field is also more general than alternatives, since a package may provide another in terms of services or libraries offered, not merely via binaries.

Without package maintainers adding information about alternatives to the Provides field (and creating virtual packages for all end points of alternatives - like vi) and without inspecting the packages themselves, there's no general way at present to till which package might provide an alternative.


I know this is a bit late, but this post is currently one of the top search hits related to finding alternatives in Debian.

The problem with using update-alternatives here is that it will only show you installed options as far as I can tell (its man page is pretty sparse).

To answer the question as posed in the title, i.e. finding all available packages that provide an alternative (whether installed or not), you can use:

aptitude search '?provides(pattern)'

which can also be abbreviated to:

aptitude search '~Ppattern'

where pattern is all or part of the alternative you are looking for. In the specific case of vi, this doesn't really work. If you inspect the packages nvi and vim with aptitude show or apt-cache show, you will see that neither one lists "vi" in its "Provides:" section. In fact, nvi's description is missing that section completely.

However, it works reasonably well for other alternatives, such as editor:

$ aptitude search '~Peditor'
p   deutex                         - composition tool for doom-style WAD files
p   edbrowse                       - /bin/ed-alike webbrowser written in C    
p   emacs24                        - GNU Emacs editor (with GTK+ GUI support) 
p   emacs24-lucid                  - GNU Emacs editor (with Lucid GUI support)
p   emacs24-nox                    - GNU Emacs editor (without GUI support)   
p   fte-console                    - Text editor for programmers - console edi
p   fte-terminal                   - Text editor for programmers - version for
p   fte-xwindow                    - Text editor for programmers - X Window Sy
p   jed                            - editor for programmers (textmode version)
p   jove                           - Jonathan's Own Version of Emacs - a compa
p   jupp                           - user friendly full screen text editor    
p   le                             - Text editor with block and binary operati
p   ledit                          - line editor for interactive programs     
p   levee                          - very small vi clone                      
p   mg                             - microscopic GNU Emacs-style editor       
p   nano                           - small, friendly text editor inspired by P
p   nano-tiny                      - small, friendly text editor inspired by P
p   ne                             - easy-to-use and powerful text editor     
p   pluma                          - official text editor of the MATE desktop 
p   rlfe                           - Front-end using readline to "cook" input 
p   rlwrap                         - readline feature command line wrapper    
p   scite                          - Lightweight GTK-based Programming Editor 
p   vigor                          - nvi with the evil paperclip              
p   vile                           - VI Like Emacs - vi work-alike            
p   vim                            - Vi IMproved - enhanced vi editor         
p   vim-athena                     - Vi IMproved - enhanced vi editor - with A
p   vim-gnome                      - Vi IMproved - enhanced vi editor - with G
i   vim-gtk                        - Vi IMproved - enhanced vi editor - with G
p   vim-nox                        - Vi IMproved - enhanced vi editor - with s
i   vim-tiny                       - Vi IMproved - enhanced vi editor - compac
p   xjed                           - editor for programmers (x11 version)     
p   xul-ext-password-editor        - edit password manager entries in Mozilla 
p   xvile                          - VI Like Emacs - vi work-alike (X11) 

Even though this isn't perfect, aptitude has incredibly flexible search capabilities that will often let you work around the problem of packages not correctly listing which alternatives they provide- for example using "~seditors ~dvi\s" as a search pattern will list all packages in the "editors" section whose description contains the string "vi ".

Another option is to uses Debian's packages website, where similar packages are listed in the section on the right.

  • 1
    Thank you for the answer. However, what is aps ~Peditor? If aps is intended to be a short cut for aptitude, fine, but please don't use that in an answer, it will just confuse everyone. Also, if you think there are missing provides, you can file a bug report against the corresponding package(s). Jul 19, 2015 at 14:57
  • From context, I think aps must stand for aptitude search. But you should use that explicitly. However, I don't think is a workable answer, regardless - maybe it will work with some refinement. aptitude search -Pvi gives a load of irrelevant stuff. I'm guessing it searches the entire package description. Jul 20, 2015 at 11:04
  • aptitude search ~P (note the tilde) searches only in Provides, but vi matches other Provides entries; you need to specify an exact match with aptitude search '~P^vi$'. This example highlights a fundamental limitation with this approach though: while there is a vi alternative, there is no vi virtual package... Feb 9, 2016 at 10:38

This depends. There are some alternatives, like x-www-browser, don't use a package and are added via maintainer scripts to the update-alternatives:

/var/lib/dpkg/info/iceweasel.postinst:    update-alternatives --install /usr/bin/x-www-browser \
/var/lib/dpkg/info/iceweasel.postinst:    update-alternatives --remove mozilla /usr/bin/iceweasel
/var/lib/dpkg/info/iceweasel.postinst:    update-alternatives --install /usr/bin/gnome-www-browser \
/var/lib/dpkg/info/iceweasel.prerm:    update-alternatives --remove x-www-browser /usr/bin/iceweasel
/var/lib/dpkg/info/iceweasel.prerm:    update-alternatives --remove gnome-www-browser /usr/bin/iceweasel
/var/lib/dpkg/info/chromium.postinst:    update-alternatives --install /usr/bin/x-www-browser \
/var/lib/dpkg/info/chromium.postinst:    update-alternatives --install /usr/bin/gnome-www-browser \
/var/lib/dpkg/info/chromium.prerm:    update-alternatives --remove x-www-browser /usr/bin/chromium
/var/lib/dpkg/info/chromium.prerm:    update-alternatives --remove gnome-www-browser /usr/bin/chromium

There are others that use a single metapackage to install any version of the same binary (Java/OpenJRE packages comes to mind, also init). Others use a virtual package, by filling up the "Provides" (this normally comes with an update to the alternatives DPKG database) in which case, any of those package should provide the same binary.

So, how to find all the packages that provides a specific file? I would use the Provides if you know a package which does, and apt-file search file for everything else.

  • Example for vim? Sep 17, 2014 at 17:14
  • 1
    @FaheemMitha vim provides editor.
    – Braiam
    Sep 18, 2014 at 0:06
  • It does. So do many other packages, including those that have nothing to do with vim. So, what would an example look like in this case? Sep 18, 2014 at 0:13

In Ubuntu, the package command-not-found contains a database containing also many alternatives. After installation, it can be queried with /usr/lib/command-not-found --no-failure-msg --ignore-installed mail (to list alternatives for mail).
Careful, when you do not want the automatic suggestions on missing commands in bash, write unset -f command_not_found_handle in your ~/.bashrc or remove the definition globally in /etc/bash.bashrc. (Do similar for zsh.)

In Debian, this tool uses only apt-file to create the database, so no alternatives are known (not tested). There it tells the same as apt-file search ....

Ubuntu source: https://launchpad.net/command-not-found

  • I don't follow what you are suggesting. Can you be more explicit? In particular /usr/lib/command-not-found /usr/bin/mail looks like some kind of recipe, but I don't understand what it is supposed to do. An explanation would be helpful. Jul 19, 2017 at 1:08
  • Added some words to clarify, and removed /usr/bin/ from the command since this does not work.
    – simohe
    Aug 1, 2017 at 19:52
  • Well, my question is about Debian, not Ubuntu. Though I don't understand why Debian and Ubuntu would differ here. And indeed the command you list does nothing useful here. # /usr/lib/command-not-found mail Command 'mail' is available in '/usr/bin/mail' mail: command not found. Aug 1, 2017 at 20:28
  • The answer tells that mail is already installed. This check can be skipped with the option --ignore-installed. But also after this, you will not get more information (in debian) than from apt-file search mail.
    – simohe
    Aug 10, 2017 at 21:54

Strictly related to the question, to find vi alternative:

 update-alternatives --list editor




update-alternatives --config vi


There are 2 choices for the alternative vi (providing /usr/bin/vi).

Selection    Path                Priority   Status


* 0            /usr/bin/vim.basic   30        auto mode

  1            /usr/bin/vim.basic   30        manual mode

  2            /usr/bin/vim.tiny    10        manual mode

Press enter to keep the current choice[*], or type selection number:
  • 4
    Right, but that only works for installed package. The question asks how to do that for all packages. Perhaps I should have been more explicit in the question. Sep 17, 2014 at 16:23
  • 1
    Correct. But I post this before checking your initial post update...the part where you add "that exist in the Debian repositories"
    – Andy
    Sep 17, 2014 at 16:26
  • Well, I had "all such packages", which I thought was clear, but apparently not. Sorry about that. Anyway, welcome to unix.sx. I see you joined today. Sep 17, 2014 at 16:29

Building on simohe's answer, and after looking at how command-not-found works on Ubuntu, here's a way to scan for commands (including command alternatives) from the package database:

grep-dctrl readline-editor /var/lib/apt/lists/*Commands-*

This assumes you have the following installed:

sudo apt install dctrl-tools command-not-found

Run sudo apt update once if command-not-found was not installed before to trigger the download of the relevant metadata; /etc/apt/apt.conf.d/50command-not-found contains a configuration snippet to download the Commands-$arch files we grepped above:

## This file is provided by command-not-found(1) to download
## Commands metadata files.

Acquire::IndexTargets {
    # The deb822 metadata files
    deb::CNF  {
        MetaKey "$(COMPONENT)/cnf/Commands-$(NATIVE_ARCHITECTURE)";
        ShortDescription "Commands-$(NATIVE_ARCHITECTURE)";
        Description "$(RELEASE)/$(COMPONENT) $(NATIVE_ARCHITECTURE) c-n-f Metadata";

# Refresh AppStream cache when APT's cache is updated (i.e. apt update)
APT::Update::Post-Invoke-Success {
    "if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi";

You must log in to answer this question.

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