Learn how to check if a specific package has been installed on your Ubuntu 16.04 from the CLI.

If you manage the installed packages on your ubuntu server, you may know that the installation of a package that is already installed may lead in some circunstances to data loss. That's why is pretty useful to verify wheter a package has been already installed or not. This can be easily done in Ubuntu using the debian package manager (dbpk).

To verify if a package has been installed with a verbose output, you can use the following command:

dpkg -s <package name> | grep Status

# example with the potrace package
dpkg -s potrace | grep Status

For example, running the previous command will show the following output in the terminal (as long as potrace isn't installed):

dpkg-query: package 'potrace' 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.

If you feel uncomfortable with all the generated output, you can use even a shorter variant that generates less output:

dpkg -l <package name>

# example with the potrace package
dpkg -l potrace

Running the previous command on a system (assuming that potrace isn't installed) would generate the following output:

dpkg-query: no packages found matching potrace

Happy server management !


Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Become a more social person

Sponsors