How to find if a package is installed or not in Linux and Unix
A while ago, we wrote an article about 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 platforms. Finding installed packages in GUI mode is easy. Just open the Menu or Dash, and enter the package name in search box. That’s all. It is simple as that. But, as you may know, there won’t be any GUI in Linux servers. So, having the ability to find out a package is installed or not in CLI mode is equally important. Now, Let us find out how can be this done in most Linux and Unix distributions.
Find if a package is installed or not in Linux
On Arch Linux:
In Arch Linux and its derivatives like Antergos and Manjaro LInux, we can do this using “pacman” command:
pacman -Qs nano
local/nano 2.6.3-1 (base) Pico editor clone with enhancements
As you can see in the above output, the nano package is installed in our Arch Linux.
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.
To find if a package (Ex.nano) is installed or not, just use:
rpm -qa | grep nano
rpm -qa | grep -i nano
To list all installed packages, run:
libpciaccess-0.13.4-2.el7.x86_64 postfix-2.10.1-6.el7.x86_64 cronie-anacron-1.4.11-14.el7_2.1.x86_64 aic94xx-firmware-30-6.el7.noarch numactl-libs-2.0.9-6.el7_2.x86_64 [...] yum-plugin-fastestmirror-1.1.31-34.el7.noarch gpgme-1.3.2-5.el7.x86_64 dhclient-4.2.5-42.el7.centos.x86_64 alsa-tools-firmware-1.0.28-2.el7.x86_64 libsoup-2.48.1-3.el7.x86_64
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.
To search if a particular package (Ex.nano) is installed or not, use:
dpkg -s nano
Package: nano Status: install ok installed Priority: important Section: editors Installed-Size: 684 Maintainer: Ubuntu Developers <firstname.lastname@example.org> Architecture: amd64 Version: 2.5.3-2 Replaces: pico Provides: editor Depends: libc6 (>= 2.14), libncursesw5 (>= 6), libtinfo5 (>= 6) Suggests: spell Conflicts: pico Conffiles: /etc/nanorc 948457d1e1e7372b50509b6314f323c4 Description: small, friendly text editor inspired by Pico GNU nano is an easy-to-use text editor originally designed as a replacement for Pico, the ncurses-based editor from the non-free mailer package Pine (itself now available under the Apache License as Alpine). . However, nano also implements many features missing in pico, including: - feature toggles; - interactive search and replace (with regular expression support); - go to line (and column) command; - auto-indentation and color syntax-highlighting; - filename tab-completion and support for multiple buffers; - full internationalization support. Original-Maintainer: Jordi Mallach <email@example.com> Homepage: http://www.nano-editor.org/
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, 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 complete details of this command in hand.
Alternatively, there are some more commands available to find the installed packages.
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 inspi
Here is another one.
dpkg --get-selections | grep nano
Here is some few more commands to find if a package is installed or not.
dpkg --list | grep nano
ii nano 2.5.3-2 amd64 small, friendly text editor inspired by Pico
Or, use the following command:
dpkg --list | grep -i nano
To view list of all installed packages, run:
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 accountsservice 0.6.40-2ubuntu11.1 amd64 query and manipulate user account information ii acl 2.2.52-3 amd64 Access control list utilities ii acpid 1:2.0.26-1ubuntu2 amd64 Advanced Configuration and Power Interface event daemon ii adduser 3.113+nmu3ubuntu4 all add and remove users and groups [...] ii xml-core 0.13+nmu2 all XML infrastructure and XML catalog file support ii xz-utils 5.1.1alpha+2012061 amd64 XZ-format compression utilities ii zerofree 1.0.3-1 amd64 zero free blocks from ext2, ext3 and ext4 file-systems ii zlib1g:amd64 1:1.2.8.dfsg-2ubun amd64 compression library - runtime
Find if a package is installed or not in Unix
I will be demonstrating this using FreeBSD 10.3. I never tried any other BSD operating systems except FreeBSD. There may 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
nano-2.4.3 Nano's ANOther editor, an enhanced free Pico clone
To view all installed packages, you can use the following command:
pkg version -v
gettext-runtime-0.19.6 GNU gettext runtime libraries and programs indexinfo-0.2.4 Utility to regenerate the GNU info page index nano-2.4.3 Nano's ANOther editor, an enhanced free Pico clone pkg-1.8.7_1 Package manager sudo-1.8.15 Allow others to run commands as root
This will take a few seconds to minute depending upon the number packages you have in your FreeBSD system.
That’s all for today. Hope this guide will help you to find the installed packages in Linux and Unix distributions. If you know any other methods, feel free to let us know in the comment section below.
I will be here with another article soon. If you find this guide useful, please share it on your social networks and support OSTechNix.
Thanks for stopping by!
How can I benefit from this blog:
- Subscribe to our Email Newsletter : Sign Up Now
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Facebook | Twitter | Google Plus | LinkedIn | RSS feeds
Have a Good day!!