Sep 102018
 

This morning I was checking via the command line to see if MySQL Server was installed on my Linux Mint 18 (Sarah) system and fumbled around a bit about how to do it.

Presumably, there are many other Linux users who wish to install a package and unsure how to check it on the command line.

So I decided to do this blog post on the various ways to check if a particular package is installed on a Linux Mint or Ubuntu system.

For each unique method, I will illustrate with two examples (the first example for a package not installed and the second for a package that’s already installed).

1. apt-cache policy Method

Not Installed

$ apt-cache policy mysql-server
N: Unable to locate package mysql-server

apt-cache policy is a quick way to determine if a particular package is installed on a Ubuntu or Linux Mint system.

Already Installed

$ apt-cache policy grsync
grsync:
  Installed: 1.2.5-1
  Candidate: 1.2.5-1
  Version table:
 *** 1.2.5-1 500
        500 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
        100 /var/lib/dpkg/status
2. dpkg -l Method

Not Installed

$ dpkg -l | grep mysql-server

Since mysql-server is not on my system, I did not get any output when I ran the dpkg -l | grep mysql-server command.

Already Installed

$ dpkg -l | grep grsync
ii  grsync        1.2.5-1       amd64        GTK+ frontend for rsync
3. dpkg-query Method

Let’s now consider the dpkg-query way to see if a specific package is installed on Ubuntu or Linux Mint.

Not Installed

$ dpkg-query -s mysql-server
dpkg-query: package 'mysql-server' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.

The above example clearly demonstrates that mysql-server is not installed on my Linux Mint 18 PC.

Already Installed

$ dpkg-query -s grsync
Package: grsync
Status: install ok installed
.....output truncated
4. dpkg -s Method

dpkg -s package_name is another quick way to determine if a package is installed on an Ubuntu system.

Not Installed

$ dpkg -s mysql-server | grep Status
dpkg-query: package 'mysql-server' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.

Already Installed

$ dpkg -s cherrytree | grep Status
Status: install ok installed
5. apt list Method

Not Installed

$ apt list mysql-server
Listing... Done
mysql-server/xenial-updates,xenial-updates,xenial-security,xenial-security 5.7.23-0ubuntu0.16.04.1 all

Already Installed

$ apt list firefox
Listing... Done
firefox/sarah,now 61.0.1+linuxmint1+sylvia amd64 [installed]
N: There is 1 additional version. Please use the '-a' switch to see it
6. dpkg -l | grep package Method

Not Installed

$ dpkg -l | grep mysql-server

Since mysql-server is not installed on my Linux desktop, the above example did not produce any output.

Already Installed

$ dpkg -l | grep firefox
ii  firefox                     61.0.1+linuxmint1+sylvia            amd64        Safe and easy web browser from Mozilla
ii  firefox-locale-en           61.0.1+linuxmint1+sylvia            amd64        English language pack for Firefox

Sorry, the comment form is closed at this time.