Tag Archives: check if package is installed in redhat

How to check if the package is installed on Linux

Learn to check if the package is installed on the Linux server or not. Verify if the package available on the server along with its installed date.

Check if package in installed on Linux

Package installation on Linux sometimes fails with error package is already installed; nothing to do. To avoid this you need to first check if the package is installed on system or not and then attempt its installation. In this article, we will be seeing different ways we can check if the package is installed on the server and also check its installation date.

Package management related reads :

Different ways to check if package is installed or not :

On RPM based system

RPM-based systems like Red Hat, CentOS, etc, we can use rpm query command like below :

# rpm -qa |grep telnet
telnet-0.17-60.el7.x86_64
OR
# rpm -q telnet
telnet-0.17-60.el7.x86_64

We are using -qa i.e. query all options which will list all installed packages on the system. We are grepping out our desired (telnet in this example) package name. If the output is blank then the package is not installed. If it’s installed then the respective name will be shown (like above). To understand what these numbers in package name mean read package naming conventions.

Or even directly querying the package name will yield you the same result as the second example above.

If the system is configured with YUM then it can list all installed packages for you and you can grep out your desired package from it.

# yum list installed telnet
Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
Installed Packages
telnet.x86_64                                                            1:0.17-60.el7                                                            @rhui-REGION-rhel-server-releases
OR
# yum list installed |grep telnet                                                                                                                        
telnet.x86_64                    1:0.17-60.el7              @rhui-REGION-rhel-server-releases

On APT based systems

APT based systems like Debian, Ubuntu, etc, dpkg command can be used to verify if the package is installed –

# dpkg -l |grep telnet
ii  telnet                           0.17-40                            amd64        basic telnet client

Column wise fields in output are Name, Version, Architecture, Description.

If you have an apt repository configured then you can try to install emulation of the desired package. If it’s installed then the respective message will be shown in output (highlighted line below). If it’s not installed then output just emulates installation process and exits without actually installing.  –

# apt-get install -s telnet
Reading package lists... Done
Building dependency tree
Reading state information... Done
telnet is already the newest version (0.17-40).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Package installation date

One of the Linux interview questions is how to find the package installation date? or how to check when the package was installed in Linux? Answer is –

On YUM based systems

rpm command has a direct option of sorting packages with their installed date --last. Grep your desired package and you will get its installed date.

# rpm -qa --last |grep telnet
telnet-0.17-60.el7.x86_64                     Fri 10 Mar 2017 01:58:17 PM EST
On APT based systems

Here there is no direct command which shows installation date. You have to grep ‘install’ word through installer log files /var/log/dpkg.log to get the installation date. If logrotate is configured on the system then use wild card * to search through all rotated and current log files.

If you observe this file does not exist on your server then install operation wasn’t performed on that system after its setup. On the very first install operation (using apt-get or dpkg) this file will get created and start logging installation details.

# grep install /var/log/dpkg.log* |grep telnet
2017-03-10 19:26:30 status installed telnet:amd64 0.17-40
2017-03-10 19:26:30 status half-installed telnet:amd64 0.17-40
2017-03-10 19:26:40 install telnet:amd64 0.17-40 0.17-40
2017-03-10 19:26:40 status half-installed telnet:amd64 0.17-40
2017-03-10 19:26:40 status installed telnet:amd64 0.17-40