sodcalculator

10 Tech How-To

Check if a Package Is Installed on Linux

Guide 10-50407 · Updated · Step by step

To find out if a package is installed on Linux, use your distribution’s package manager query command, such as dpkg -s on Debian/Ubuntu or rpm -q on RHEL/Fedora. This article explains the exact commands for major package managers, how to interpret their output, and what to do when a package was installed from source or as a snap/flatpak.

Why You Need to Check Installed Packages

Knowing whether a specific package is installed is a routine but essential task for Linux administrators and users. You might need to verify that a dependency is present before compiling software, confirm that a security update was applied, or simply check whether a tool you want to use is already available. Each Linux distribution uses a different package manager, so the command varies. Using the wrong command for your system will produce a confusing error, so it’s important to match the command to the distro.

Checking with APT (Debian, Ubuntu, Mint)

Debian-based systems use the dpkg backend with the apt frontend. The most direct way to check is with dpkg:

dpkg -s package-name

This prints a status block. Look for the line Status: install ok installed. If the package is not installed, you’ll see dpkg-query: package 'package-name' is not installed and no information is available.

Alternatively, use apt to show only installed packages:

apt list --installed | grep package-name

For a quick exit-code check (useful in scripts), use:

dpkg -s package-name >/dev/null 2>&1 && echo "installed" || echo "not installed"

Checking with RPM (RHEL, Fedora, CentOS, Rocky)

Red Hat–based distributions use the rpm package manager. The simplest command is:

rpm -q package-name

If installed, it prints the full name and version, e.g., bash-5.1.8-6.el9.x86_64. If not, it prints package package-name is not installed and returns a non-zero exit code.

To see all installed packages that match a pattern:

rpm -qa | grep package-name

For a script-friendly check, use:

rpm -q package-name && echo "installed" || echo "not installed"

Checking with Pacman (Arch, Manjaro)

Arch-based systems use pacman. To check if a package is installed:

pacman -Q package-name

This prints the package name and version if installed, or an error like error: package 'package-name' was not found. To search all installed packages for a partial name:

pacman -Qs package-name

Checking with Zypper (openSUSE)

openSUSE uses zypper and rpm. The rpm commands above work, but zypper provides a friendlier search:

zypper se --installed-only package-name

Or use rpm -q directly as shown earlier. For a script check:

rpm -q package-name && echo "installed" || echo "not installed"

Handling Snap, Flatpak, and Source Installs

Modern Linux systems often use universal package formats that aren’t tracked by the native package manager.

  • Snap: Run snap list to see all installed snaps, or snap info package-name to check a specific one.
  • Flatpak: Run flatpak list to see installed flatpaks, or flatpak info package-name for a specific app.
  • Source installs: Software compiled from source (via make install) is not registered with any package manager. Check for the binary in /usr/local/bin or use which package-name to see if it’s in your PATH.

A common misconception is that which or command -v tells you if a package is installed. These only show if a program is in your PATH, not whether it was installed via a package manager. A program could be present as a user script or a binary downloaded manually, and still not be a “package” in the system’s database.

Common Problems and Troubleshooting

If you get a “command not found” error when trying to run the package manager itself, your PATH may be misconfigured, or you are using a minimal container image that lacks the package manager. On a normal desktop distro, this is rare.

Another issue: dpkg -s returns an error for packages that were removed but not purged. The status line will show deinstall ok config-files instead of install ok installed. This means the package’s configuration files remain, but the software is not installed. Use dpkg -l | grep package-name to see the exact state.

For RPM-based systems, rpm -q only checks the RPM database. If you installed a program via a vendor script (e.g., a .run file), it won’t appear. In that case, look for the executable with which or check common installation directories.

Comparing Package Managers at a Glance

Here is a quick reference for the most common distro families:

  • Debian/Ubuntu: dpkg -s or apt list --installed
  • RHEL/Fedora/CentOS: rpm -q or dnf list installed
  • Arch/Manjaro: pacman -Q
  • openSUSE: rpm -q or zypper se --installed-only
  • Alpine: apk info -e package-name

Each command returns a non-zero exit code if the package is not found, which makes them suitable for shell scripts. For example, you can write a conditional that installs the package only if it’s missing.

Frequently Asked Questions

What does “dpkg-query: package is not installed” mean?

It means the package is not in the dpkg database. The package either was never installed, was removed and purged, or was installed via a different method (like a .deb file that you manually extracted). Double-check the exact package name, as names are case-sensitive and often include version suffixes.

How do I check if a package is installed without using the terminal?

Most desktop environments have a graphical software center (e.g., GNOME Software, KDE Discover) that shows installed applications, but they don’t list every low-level library or command-line tool. For a complete view, the terminal is the only reliable way. You can also use a GUI package manager like Synaptic on Debian/Ubuntu, but it still queries the same dpkg database.

Why does ‘which’ not show a package even though it’s installed?

which searches your PATH environment variable for an executable. If the package’s binary is in a directory not listed in PATH (e.g., /usr/sbin for non-root users, or /usr/libexec), which won’t find it. Also, some packages install only libraries or data files, not executables. Use the package manager query instead.

Can I check if a package is installed on a remote Linux server?

Yes, you can SSH into the server and run the same commands. For example: ssh user@server "dpkg -s nginx" will show the status on the remote machine. This works as long as you have SSH access and the necessary permissions to run the package manager query (usually no sudo is needed for queries).

What is the difference between ‘dpkg -s’ and ‘apt list –installed’?

dpkg -s checks the low-level package database and gives detailed status, including version and architecture. apt list --installed is a higher-level command that lists all installed packages and can be filtered with grep. Both use the same underlying database, so results are consistent. Use dpkg -s for a single package check, and apt list --installed for a broad search.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →