How to Find Out if a Package is Installed on Linux or Not?

Several articles have been written in the past about this topic.

Each article is written for different purposes, and you can check them out by going to the link below.

Go to the following article to verify Linux GUI Package Managers.

All major distributions come with their own CLI Package Manager, which allows you to easily verify this information.

If you already work as a Linux administrator, this will be an easy task for you.

However, for newcomers this can be a bit difficult to find. I recommend them to use the GUI tool described above.

Let us see how we can do this in detail.

1) How to Find Out if a Package is Installed on Linux Using General Commands?

As described above, each distributions come with its own package manager, which allows you to verify this information.

However, there are some common commands in Linux that allow you to check this information regardless of the distribution.

1a) How to Find Out if a Package is Installed on Linux Using the which Command?

The which command returns an executable path that can be executed when the command is entered in the terminal.

This is especially useful if you want to create a desktop shortcut or symbolic link for executable files.

Which command searches directories listed in the current user’s PATH environment variable, not for all users.

This means that when you are logged into your own account, you cannot search for the root user file or directory.

Run the following command to print the full path of the VIM executable file location. If VIM package is installed on your computer, it will show the installed path as shown below.

# which vi
/usr/bin/vi

1b) How to Find Out if a Package is Installed on Linux Using the whereis Command?

The whereis command used to search the binary, source, and man page files for a given command.

If the following output shows the location of a given package binary or executable file, the given package is already installed on the system. Otherwise, the package is not installed on the system.

# whereis vi
vi: /usr/bin/vi /usr/share/man/man1/vi.1p.gz /usr/share/man/man1/vi.1.gz

1c) How to Find Out if a Package is Installed on Linux Using the Locate Command?

The Locate command performs faster than the Find command because it uses an updatedb database, whereas the find command searches in real time.

It uses a database rather than looking for individual directory paths to get a given file.

The Locate command is not already installed on most distributions, so use your distribution package manager to install it.

The database is constantly updated by Cron. Even then, we can update it manually.

If the following output shows the location of a given package binary or executable file, the given package is already installed on the system. Otherwise, the package is not installed on the system.

# locate --basename '\nano'
/usr/bin/nano
/usr/share/nano
/usr/share/doc/nano

2) How to find out if a package is installed on Arch Linux?

Use pacman Package Manager to find this information in Arch Linux and its derivatives like Manjaro, etc.,

If the below command returns nothing then the given package is not installed in system.

$ pacman -Qs nano
local/nano 4.3-1 (base)
    Pico editor clone with enhancements

3) How to find out if a package is installed on CenOS / Red Hat (RHEL) Linux?

Use yum Package Manager or rpm Package Manager to find this information on Red Hat and their clones like CentOS, Oracle Linux.

Find out if a package is installed using the yum command.

# yum list installed openssh
Loaded plugins: fastestmirror, universal-hooks
Loading mirror speeds from cached hostfile
 * EA4: 203.174.85.202
 * cpanel-addons-production-feed: 203.174.85.202
 * cpanel-plugins: 203.174.85.202
 * base: centos.netonboard.com
 * epel: mirror.airenetworks.es
 * extras: centos.netonboard.com
 * nux-dextop: mirror.li.nux.ro
 * updates: centos.netonboard.com
Installed Packages
openssh.x86_64                                                                                          7.4p1-16.el7                                                                                          @base

Find out if a package is installed using the rpm command.

# rpm -qa nano
nano-2.3.1-10.el7.x86_64

4) How to find out if a package is installed on Fedora Linux?

Use the dnf Package Manager or rpm package manager to find this information on Fedora Linux.

Find out if a package is installed using the dnf command.

# dnf list installed httpd
Last metadata expiration check performed 0:44:26 ago on Tue Jun  9 22:52:44 2019.
Installed Packages
httpd.x86_64                        2.4.12-1.fc22                        @System

Find out if a package is installed using the rpm command.

# rpm -qa nano

5) How to find out if a package is installed on Ubuntu / Debian Linux?

There are several commands in the Debian-based system (Ubuntu, Linux Mint, etc.) to find this information.

Use one of the following commands to find this information: apt Package Manager or apt-cache command or dpkg-query command or dpkg Package Manager.

Find out if a package is installed using the apt-cache command.

# apt-cache policy nano
nano:
  Installed: 2.9.3-2
  Candidate: 2.9.3-2
  Version table:
 *** 2.9.3-2 500
        500 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 Packages
        100 /var/lib/dpkg/status

Find out if a package is installed using the apt command.

# apt -qq list nano
nano/bionic,now 2.9.3-2 amd64 [installed]

Find out if a package is installed using the dpkg-query command.

# dpkg-query --list | grep -i nano
ii  nano    2.9.3-2    amd64    small, friendly text editor inspired by Pico

Find out if a package is installed using the dpkg command.

# dpkg -l | grep -i nano
ii  nano     2.9.3-2    amd64   small, friendly text editor inspired by Pico

6) How to find out if a package is installed on openSUSE Linux?

Use the zypper Package Manager or rpm package manager to find this information on openSUSE Linux.

Find out if a package is installed using the zypper command.

$ zypper se --installed-only | grep -i GIMP

Loading repository data...
Reading installed packages...

Loading repository data...
Reading installed packages...

S  | Name                                       | Summary                                                                               | Type       
---+--------------------------------------------+---------------------------------------------------------------------------------------+------------
i  | GIMP                                       | Create images and edit photographs                                                    | application

Find out if a package is installed using the rpm command.

# rpm -qa nano

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...