If you’re managing Debian or Ubuntu servers, probably, you may use **dpkg** or **apt-get** commands often. These two commands are used to install, remove, update packages.
In this brief tutorial, let us see how to check if a package is installed or not in DEB based systems.
To check whether a particular package for example firefox, is installed or not using command:
dpkg -s firefox
Sample output:
Package: firefox
Status: install ok installed
Priority: optional
Section: web
Installed-Size: 93339
Maintainer: Ubuntu Mozilla Team <ubuntu-mozillateam@lists.ubuntu.com>
ii firefox 35.0+build3-0ubuntu0.14 amd64 Safe and easy web browser from Mozilla
To list all installed package in your system, enter the following command
dpkg --get-selections
Sample output:
abiword install
abiword-common install
accountsservice install
acl install
adduser install
alsa-base install
alsa-utils install
anacron install
app-install-data install
apparmor install
.
.
.
zeitgeist install
zeitgeist-core install
zeitgeist-datahub install
zenity install
zenity-common install
zip install
zlib1g:amd64 install
zlib1g:i386 install
The above might be very long depending upon the number of packages you have installed on your system.
You can also filter through **grep** to get results for the exact package you need. For example, I want to see which gcc packages are already installed on my system using **dpkg** command:
dpkg --get-selections | grep gcc
Sample output:
gcc install
gcc-4.8 install
gcc-4.8-base:amd64 install
gcc-4.8-base:i386 install
gcc-4.9-base:amd64 install
gcc-4.9-base:i386 install
libgcc-4.8-dev:amd64 install
libgcc1:amd64 install
libgcc1:i386 install
Additionally, you can find location of the files within a package using the parameter “**-L**”.
dpkg -L gcc-4.8
Sample output:
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/gcc-4.8-base
/usr/share/doc/gcc-4.8-base/README.Bugs
/usr/share/doc/gcc-4.8-base/NEWS.html
/usr/share/doc/gcc-4.8-base/quadmath
/usr/share/doc/gcc-4.8-base/quadmath/changelog.gz
/usr/share/doc/gcc-4.8-base/gcc
.
.
.
/usr/bin/x86_64-linux-gnu-gcc-4.8
/usr/bin/x86_64-linux-gnu-gcc-ar-4.8
/usr/bin/x86_64-linux-gnu-gcov-4.8
That’s all for now. Hope this short tutorial will useful for you.