To find out if a particular package is installed on a Linux system, you can use the dpkg
command with the -l
flag and search for the name of the package. The -l
flag lists all the installed packages on the system, and you can use the grep
command to search for the package you are interested in.
For example, to find out if the nginx
package is installed, you can use the following command:
$ dpkg -l | grep nginx ii nginx 1.18.0-0ubuntu1~20.04.4 amd64 small, powerful, scalable web/proxy server
The ii
in the output indicates that the nginx
package is installed and fully configured. If the package is not installed, the dpkg
command will not produce any output.
Alternatively, you can also use the apt
command with the list
subcommand to list the installed packages on the system. The apt
command is a front-end to the dpkg
command, and it provides additional features for managing packages on the system.
For example:
$ apt list --installed | grep nginx nginx/focal-updates,focal-security,now 1.18.0-0ubuntu1~20.04.4 all [installed]
This command will list all the installed packages on the system, and you can use the grep
command to search for the package you are interested in.
Note that these commands will only work if the dpkg
or apt
package management system is used on the system. If the system uses a different package management system, such as yum
or rpm
, you will need to use a different command to list the installed packages.