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>
$ which nano
If the nano package is installed, it will display the installed path like below.
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.
The "which" command is available by default on most Unix-like operating systems.
Also, there are a 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
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 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
$ rpm -qa | grep -i nano
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
$ 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
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
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
And one more command....
$ dpkg --list | grep nano
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
To check if a package is installed or not in SUSE and openSUSE, run:
$ zypper search nano
$ 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>
$ pkg info -Ix nano
To view all installed packages, you can use the following command:
$ pkg info
$ pkg version -v
This will take a few seconds to minute depending upon the number of packages you have in your FreeBSD system.
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:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Reddit | Facebook | Twitter | LinkedIn | RSS feeds
Have a Good day!!
You can also use dnf/yum as in
dnf list packagename
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.
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.