How To Find If A Package Is Installed Or Not In Linux And Unix

A while ago, we learned how to find a package version in Linux. Today, we will see how to find if a package is installed or not in Unix-like operating systems. Finding installed packages in GUI mode is easy. All we have to do is to Just open the Menu or Dash, and enter the package name in search box. If the package is installed, you will see the menu entry. It is simple as that. But, it is difficult to find it in a system where it doesn’t has GUI mode. So, knowing how to find out a package is installed or not in CLI mode is equally important as we do in GUI mode. Now, let us find out how can we find if a package is installed or not, shall we?

Find if a package is installed or not in Linux

The most common way to find if a package is installed or not is to use “which” command like below:

$ which <package-name>

Example:

$ which nano

If the nano package is installed, it will display the installed path like below.

/usr/bin/nano

As you see, nano package is installed.

Let us check an another package, for example Emacs:

$ which emacs
/usr/bin/which: no emacs in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

See? Emacs is not installed.

The “which” command is available by default on most Unix-like operating systems.

Also, there are few few other distribution specific way to find if a package is installed or not. Read on.

On Arch Linux:

In Arch Linux and its derivatives like Antergos and Manjaro LInux, we can do this using “pacman” command like below:

$ pacman -Qs nano

Sample output:

local/nano 2.9.3-1 (base)
 Pico editor clone with enhancements

Did you notice the prefix “local” in-front of the package “nano”? It means that Nano is installed.

If the above command returns nothing, it means the given package is not installed.

On Fedora / RHEL / CentOS / Scientific Linux:

In RPM based Linux distributions like Fedora, RHEL and its clones like CentOS, Scientific Linux, we can find out if a package is installed using “rpm” command.

$ rpm -qa | grep nano

Or,

$ rpm -qa | grep -i nano

Sample output:

nano-2.3.1-10.el7.x86_64

Also, you can use Yum command like below.

$ yum list installed|grep 'nano'

To list all installed packages, run:

$ rpm -qa

On Debian / Ubuntu / Linux Mint:

In DEB based system like Debian, Ubuntu and its derivatives like Linux Mint, and Elementary OS, we can do this using “dpkg” command.

$ dpkg -s nano

Sample output:

As you see in the above output, nano package is installed in our Ubuntu system. This command not only shows whether the specified package is installed or not, but also the priority of the package, version number, maintainer name, dependencies, and its description etc. You don’t need to refer man pages or any online pages, just run this command to have the complete details of this command in hand.

This is not the only way to find the installed packages. Here are some more commands.

$ dpkg-query -l nano

Sample output:

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-=================================
ii nano 2.5.3-2 amd64 small, friendly text editor inspired by Pico

Here is another one.

$ dpkg --get-selections | grep nano

Sample output:

nano install

And one more command….

$ dpkg --list | grep nano

Sample output:

ii nano 2.5.3-2 amd64 small, friendly text editor inspired by Pico

Or, use this command:

$ dpkg --list | grep -i nano

To view list of all installed packages, run:

$ dpkg --list

On SUSE/openSUSE:

To check if a package is installed or not in SUSE and openSUSE, run:

$ zypper search nano

Or, shortly:

$ zypper se nano

You can also use “rpm” command like below.

$ rpm -q nano

Find if a package is installed or not using “has” utility

Trust me, this is super easy! The “has” utility will check the presence of various command line tools on the path and also reports their installed version.

To install it run the following commands:

$ git clone https://github.com/kdabir/has.git 
$ cd has 
$ sudo make install

Now check if a package is available or not like below.

$ has nano
✔ nano 2.5.3

If you see the tick mark (✔), the package is installed. As you see in the above output, nano package is installed and its version is 2.5.3.

You will see the cross mark if the package is not installed. Check the following example.

$ has emacs
✘ emacs

You can check for multiple packages as well.

$ has nano emacs vim
✔ nano 2.5.3
✘ emacs
✔ vim 7.4

If you don’t want to install it, you can directly use it like below. Your system must be connected with Internet.

$ curl -sL https://git.io/_has | bash -s nano

To check for multiple packages:

$ curl -sL https://git.io/_has | bash -s nano emacs vim

Create an alias if you’re too lazy to type the whole command:

$ alias has="curl -sL https://git.io/_has | bash -s"

Now, just use this utility like below:

$ has nano

For more details, refer the project’s GitHub page.

Find if a package is installed or not in Unix

The below steps were tested in FreeBSD 10.3. I never tried any other BSD operating systems except FreeBSD. So, there might be different commands to find out if a package installed in other BSD operating systems.

In FreeBSD, we can do this using “pkg” command:

$ pkg_info -Ix <package-name>

Example:

$ pkg info -Ix nano

Sample output:

To view all installed packages, you can use the following command:

$ pkg info

Or,

$ pkg version -v

This will take a few seconds to minute depending upon the number of packages you have in your FreeBSD system.

Conclusion

You know now how to find if a package is installed or not using the official and non-official way from command line. As you can see, it is not that difficult. It’s just a couple commands which you can easily remember. If you can’t remember these commands, just bookmark them or save them in the Terminal itself to run on demand.

And, that’s all for today. Hope this guide was useful. If you know any other methods, feel free to let us know in the comment section below. More good stuffs to come. Stay tuned!

Cheers!

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You may also like...

3 Responses

  1. xircon says:

    which e.g.
    which nano
    /usr/bin/nano

  2. Gregory Pittman says:

    You can also use dnf/yum as in
    dnf list packagename
    or even
    dnf list package*
    What you get from these is a list of what’s installed and also what’s available in repositories. dnf allows a wildcard, and will also be case-insensitive in its search. Sometimes you don’t quite know what you’re looking for or the correct spelling.

  3. Há Zé says:

    Dear SK, please take a look at the manual of which command! It finds an executable if the directory which contains it, is in the path of your current environment.

Leave a Reply

Your email address will not be published. Required fields are marked *