Home Command line utilities How To Find If A Package Is Installed Or Not In Linux And Unix
Find If A Package Is Installed Or Not In Linux And Unix

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

By sk
10827 Views

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 Linux and Unix 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 bit 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 in /usr/bin/ path.

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.

Find if a package is installed or not in Linux Using Which Command

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

Also, there are 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

Find if a package is installed or not in Arch Linux Using Pacman

Did you notice the prefix "local" in-front of the package "nano"? It means that Nano is installed on your system.

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

On Fedora / RHEL / CentOS / Scientific Linux:

In RPM based Linux distributions such as Fedora, RHEL and RHEL clones like CentOS, Scientific Linux, we can find out if a package is installed using "rpm" command as shown below.

$ 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

As one of our reader "Gregory Pittman" mentioned in the comment section below, we can use dnf command in Fedora to find the installed package.

$ dnf list packagename

or even

$ dnf list package*

What you get from these is a list of what is installed and also what is 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.

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:

Find if a package is installed or not in Debian, Ubuntu Linux Using dpkg command

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.

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 though.

$ 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:

Find if a package is installed or not in FreeBSD Using pkg command

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.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

3 comments

xircon September 3, 2016 - 4:36 am

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

Reply
Gregory Pittman September 6, 2016 - 4:25 am

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.

Reply
Há Zé February 7, 2018 - 8:23 pm

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.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More