In the next article we are going to take a look at how we can check from terminal if a given package is installed or not on our Ubuntu system. Sometimes users may need to know this information for one thing or another.
To obtain this information, we can find different ways to obtain it. Searching a bit in Google you can find different ways of obtaining this data. Which is something that at some point can always be useful for all users. In this article we are going to leave seven ways, so that each user can choose the one that best suits him.
What can we use from the terminal to check if a given package is installed or not on Ubuntu?
- apt This is a powerful command line tool to install, download, remove, search and manage packages on Debian-based systems.
- APT-Cache. Used to query the APT cache or metadata of a package.
- dpkg. It is a package manager for Debian-based systems.
- DPKG-Query. This is a tool for query the dpkg database.
- which. This command returns the full path of the executable.
- where's. Is used for find the binary, source, and man page files for a given command.
- locate. The locate command works faster than find command because it uses the updatedb database, while the find command searches the real system.
Examples to check if a package is installed
First of all, say that I have the following commands tested on Ubuntu 19.04.
Apt command
APT is a powerful tool for the terminal with which we can install, download, delete, search and manage, as well as consult information about packages. It also contains some less used command line utilities related to package management.

apt list vim
Apt-cache command
The command apt-cache used to query APT cache or package metadata from APT internal database. It will search and display information about the given package. It will show us if the package is installed or not, the version of the installed package, the information of the source repository.
In the following example we will see that the vim package has already been installed on the system.

apt-cache policy vim
Dpkg command
DPKG It is a tool for installing, creating, removing and managing packages, but unlike other package management systems, cannot automatically download and install packages or their dependencies. To get the information, clearly, we can combine it with grep.

dpkg -l | grep -i nano
Dpkg-query command
This is a tool for display information about the packages listed in the dpkg database.

dpkg-query --list | grep -i nano
Which command
The which command returns the full path of the executable. This command is very useful when we want to create a desktop shortcut or a symbolic link for executable files. The command searches the directories listed in the environment variable PATH current user.
If after executing the command the binary of the given package or the location of the executable file is displayed, this indicates that the package has already been installed on the system. If not, the package is not installed on the system.

which vim
Whereis command
The command where's used to find the binary, source, and man page files for a given command.
If the output of the command shows the binary of the given package or the location of the executable file, it indicates that the package has already been installed on the system. If not, the package is not installed on the system.

whereis nano
Locate command
The command locate works faster than find command because it uses updatedb database, while the find command searches the real system. Use a database instead of searching for individual directory paths.
If the command output shows the given package binary or executable file location, the package has already been installed on the system. If not, the package is not installed on the system.

locate --basename '\nano'