How to Find Which Ubuntu/Debian Package Provides a Specific Command-Line Program


2 views

On Debian-based systems like Ubuntu, we have several powerful tools to identify which package provides a particular binary:

# Search for packages providing the 'htop' command
apt-file search bin/htop

# Alternative using dpkg
dpkg -S $(which htop)

# For installed packages only
dpkg -l | grep htop

The apt-file command is particularly useful as it searches through the contents of all available packages, not just installed ones. First, you'll need to install and update it:

sudo apt update
sudo apt install apt-file
sudo apt-file update

Then you can search for any program:

# General search pattern
apt-file search bin/program_name

# Real-world example for curl
apt-file search bin/curl

Let's walk through some common scenarios:

# Case 1: Finding the ifconfig package
apt-file search bin/ifconfig
# Output reveals it's in net-tools

# Case 2: Locating php-cli
apt-file search bin/php
# Shows multiple PHP-related packages

For quick checks on already installed packages:

# Using which and dpkg together
dpkg -S $(which nano)

# Using apt-cache (less precise)
apt-cache search --names-only ^nano$
  • Include the bin/ prefix in searches to narrow results to executables
  • Use grep to filter results when dealing with common terms
  • Remember that some programs might be provided by multiple packages (like python vs python3)

For frequent use, create a simple bash function in your ~/.bashrc:

pkgfind() {
    apt-file search bin/$1 | grep -w $1 | cut -d: -f1 | sort -u
}

Then you can simply run:

pkgfind htop

When working with Ubuntu or other Debian-based systems, you'll often encounter situations where you know a command but need to install its package. Unlike RPM-based systems that use rpm --whatprovides, Ubuntu provides several efficient methods to discover package-command relationships.

The most powerful tool for this purpose is apt-file, which searches the contents of packages in your available repositories:

sudo apt update
sudo apt install apt-file
apt-file update
apt-file search bin/xclock

This will return results like:

x11-apps: /usr/bin/xclock

For commands already installed on your system, use:

dpkg -S $(which xclock)

Or more explicitly:

dpkg -S /usr/bin/xclock

Ubuntu's newer versions include:

apt search --names-only ^package-name$

Or using regex:

apt search 'xclock$'

For systems without internet access or when you want to verify availability:

wget -qO - https://packages.ubuntu.com/search?keywords=xclock&searchon=contents | grep -A1 "Package:"

Let's solve common scenarios:

# Find which package provides 'dig'
apt-file search bin/dig

# Locate package for 'ifconfig'
dpkg -S $(which ifconfig)

# Discover package containing 'nslookup'
apt search --names-only ^.*nslookup$

Add these to your ~/.bashrc for convenience:

alias whatprovides="apt-file search"
alias whatinstalled="dpkg -S"

If a command isn't found, first verify it's actually missing:

type -a command_name || whereis command_name

Then check if it's a shell builtin or alias before searching packages.

For those transitioning from RPM-based systems:

RPM Command Debian Equivalent
rpm -q --whatprovides apt-file search
rpm -qf dpkg -S