command line, linux, shell

How to determine if software is already installed on Linux

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ 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
[...]
$ 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 [...]
$ 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.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ rpm -q python
python-2.7.5-18.el7_1.1.x86_64
$ rpm -q python python-2.7.5-18.el7_1.1.x86_64
$ 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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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
# 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
# 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