To check whether a package is installed on Linux, use the command for your distribution’s package manager: for example, dpkg -s package-name on Debian or Ubuntu, or rpm -q package-name on Fedora and other RPM-based systems. Replace package-name with the package’s actual name; a command-line program’s name may be different.
Identify Your Linux Distribution
Linux distributions do not all use the same package format or management tools. First identify the distribution, then choose the matching query command. You can inspect /etc/os-release with:
cat /etc/os-release— prints distribution details, including its name and version.command -v apt,command -v dnf, orcommand -v pacman— checks whether one of these commands is available.
Common families include Debian and Ubuntu, which use Debian packages and tools such as dpkg and apt; Fedora and many related distributions, which use RPM packages managed by rpm and dnf; and Arch Linux, which uses pacman. Other systems may use different tools, so do not assume a command is available just because it appears in a guide for another distribution.
Check Packages on Debian and Ubuntu
For a package known by its Debian package name, run:
dpkg -s package-name
If it is installed, the output includes a status line such as Status: install ok installed. If it is not installed, dpkg reports that it cannot find the package. To make a concise check in a shell script, use:
dpkg-query -W -f='${Status}\n' package-name
When installed, the output is typically install ok installed. You can also check the command’s exit status:
if dpkg-query -W -f='${Status}' package-name 2>/dev/null | grep -q 'install ok installed'; then
echo 'Installed'
else
echo 'Not installed'
fi
This tests the package database rather than whether a similarly named command happens to be on your PATH. For a quick interactive search, apt list --installed package-name can help, but its output may include matching names or version information that is less convenient for scripts. Use dpkg-query when you need to test a specific package precisely.
Check Packages on Fedora and Other RPM Systems
On an RPM-based system, query the installed package database with:
rpm -q package-name
If installed, the command prints the package name and version. If it is absent, it reports that the package is not installed. On systems using DNF, you can also run:
dnf list --installed package-name
The rpm -q command is a direct way to ask whether a named RPM package is present. DNF can be useful when you want package-manager context, but its output format may vary. For a script, rely on the command’s exit status rather than matching a translated or version-dependent message:
if rpm -q package-name >/dev/null 2>&1; then
echo 'Installed'
else
echo 'Not installed'
fi
Check Packages on Arch Linux
On Arch Linux, query the local package database with:
pacman -Q package-name
An installed package is printed with its version; a missing package produces an error. For a simple script, check the exit code:
if pacman -Q package-name >/dev/null 2>&1; then
echo 'Installed'
else
echo 'Not installed'
fi
pacman -Q asks about locally installed packages. By contrast, commands that search remote repositories answer whether a package is available to install, which is not the same question.
Package Name, Program Name, and Installation Scope
A common source of confusion is that the name you type to launch software may not match the package name. For example, a package can install several commands, or a command can be provided by a differently named package. If a command works but a package query says “not installed,” look up which package provides that command using your distribution’s package information or documentation.
Also distinguish system packages from software installed by other means. These package-manager queries generally check the operating system’s package database; they may not detect an application installed as a Flatpak, Snap, AppImage, language-specific package, or manually copied files. Check the relevant tool when you know the installation method. For example, flatpak list lists installed Flatpak applications, while snap list lists installed Snaps when Snap is available.
Root privileges are normally not required just to query the installed package database. Avoid using sudo unless a particular system or command reports that permission is needed. A package being installed also does not prove that its service is running, that its executable is accessible to your user, or that it is configured correctly; those require separate checks.
Common Problems and Reliable Checks
- Wrong package name: Search for the distribution’s package name rather than guessing from the executable name.
- Wrong package manager: A command such as
dpkgwill not query an RPM or Arch package database. - Repository search mistaken for an installed check: A package being available online does not mean it is installed locally.
- Output mistaken for a yes-or-no result: Use the command’s exit status in scripts. Human-readable messages can vary between tools and versions.
- Software installed outside the system package manager: Check its installation tool or location separately; the system package database may not know about it.
For scripts that must support several distributions, detect available package tools and use the appropriate query for each supported family. Do not treat “the query command failed” as definitive proof that a package is absent: the failure could also mean the tool is missing, the package name is invalid, or the database cannot be accessed.
Frequently Asked Questions
How do I check if a package is installed from the terminal?
Use the package manager’s local query: dpkg -s name or dpkg-query on Debian-based systems, rpm -q name on RPM systems, and pacman -Q name on Arch.
How can I check without installing anything?
These commands query the local package database and do not install the package. You usually do not need administrator privileges for the query.
How do I check an installed package in a shell script?
Use the query command’s exit status in an if statement. For example, rpm -q name >/dev/null 2>&1 succeeds when the RPM package is installed.
Why does a command work when the package check says it is missing?
The command may come from a differently named package, a different installation method, or a location outside the package database you queried. Find its source before concluding it is absent.
Does “installed” mean the program is running?
No. A package query confirms package-database status, not whether an application or service is currently running. Check the program or service separately.
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
- Fix Error 0x80072f76 0x20016 in Windows
- How to Backup and Restore Drivers in Windows 11
- Fix Windows Couldn’t Complete the Requested Changes
- Move to iOS Stuck? Fixes That Actually Work
- USB Bluetooth Dongle: What It Is and How It Works
- ADB Device Not Found Error on Windows: Fixed