command line, linux, shell

How to determine if software is already installed on Linux

$ which gcc
/usr/bin/gcc


$ whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc

# run 'updatedb' to refresh db
$ locate gcc
/usr/bin/c89-gcc
/usr/bin/c99-gcc
/usr/bin/gcc
/usr/bin/gcc-8
/usr/bin/gcc-ar
/usr/bin/gcc-ar-8
/usr/bin/gcc-nm
/usr/bin/gcc-nm-8
[...]

Find packages using packaging utilities

If you know the name of the package you’re looking for, you can also use your system’s packaging utilities to check directly for the package’s presence.

$ rpm -q python
python-2.7.5-18.el7_1.1.x86_64

You can also find out which package a particular file belongs to:

# redhat
$ rpm -qf /etc/httpd
httpd-2.4.6-31.el7.centos.x86_64

# freebsd
$ pkg which /usr/local/sbin/httpd
/usr/local/sbin/httpd was installed by package apache24-2.4.12

# ubuntu
$ dpkg-query -S /etc/apache2
javascript-common: /etc/apache2