Commands to install rpm packages on CentOS or Redhat Linux

Although most of the time, we install RPM packages using command via the official or unofficial repository in Linux. However, it is not the only way, just like Windows on Linux too, we can directly download and install software packages using Redhat supported open-source tool called RPM Package Manager. 

Today, here we will see how to use the RPM command to install RPM packages of CentOS or RHEL. Plus also we use YUM and DNF to install RPM packages. As CentOS 8 and RHEL 8 now support dnf too.

First, log in as root or a user with sudo rights on your Linux server. You can use the command: su

Now, download the software package you want to install. For example, here we are downloading the RPM package of PHP software from its official website. Let’s say the name of it is php-5.4.16-46.el7.x86_64.rpm

RPM Command to install packages

After downloading the RPM package, first, we show the RPM command to install it on CentOS or Redhat 8/7/6.

The command is:

rpm -i packagename.rpm

How to use it:

rmp -i php-5.4.16-46.el7.x86_64.rpm

For rpm force install just use the -f flag

rmp -i -f php-5.4.16-46.el7.x86_64.rpm

So, in this way, we can simply use RPM command to install any rpm packages, however, it not resolve the dependencies of any packages require and gives error most of the time. If you have some packages that need some extra packages while installing it, use the YUM command shown in this article.

The output for the above command:

 [root@DESKTOP-9OOKS69 ~]# rpm -i php-5.4.16-46.el7.x86_64.rpm
 error: Failed dependencies:
         httpd-mmn = 20120211x8664 is needed by php-5.4.16-46.el7.x86_64
         php-common(x86-64) = 5.4.16-46.el7 is needed by php-5.4.16-46.el7.x86_64
         php-cli(x86-64) = 5.4.16-46.el7 is needed by php-5.4.16-46.el7.x86_64
         httpd is needed by php-5.4.16-46.el7.x86_64 

RPM uninstall command

If you want to use the same RPM command to uninstall or remove some installed package or software then it will be like this:

Structure of the command:

rpm -e package_name

Example to use it:

rpm -e php-5.4.16-46.el7.x86_64.rpm

The difference is the flag used with the RPM command i.e -e for uninstalling whilst if you use -i, the same command will use to install.

Use RPM to list all installed packages

For information to see what are the packages currently installed on your system you can use this command:

 rpm -qa 

Furthermore, to see the total number of packages installed on your system in figures we can use a command:

rpm -qa | wc -l

Yum command to install rpm with dependencies

Yes, we can use YUM to install RPM packages, the benefit of this command as told above, it has the capability to download & install the dependencies a software needs while installing it on CentOS 8/7/6 or RHEL 8/7/6 based Linux systems…

The command structure is:

yum install package-name

Example: How to use it

yum install php-5.4.16-46.el7.x86_64.rpm

The output of above command:

--------------------------------------------------------------
We used Yum install command to install the same package it has successfully 
resolve the dependencies requires by PHP to install which was not possigble with the above RPM command.

 [root@DESKTOP-9OOKS69 ~]# yum install php-5.4.16-46.el7.x86_64.rpm
 Loaded plugins: fastestmirror
 Examining php-5.4.16-46.el7.x86_64.rpm: php-5.4.16-46.el7.x86_64
 Marking php-5.4.16-46.el7.x86_64.rpm to be installed
 Resolving Dependencies
 --> Running transaction check
 ---> Package php.x86_64 0:5.4.16-46.el7 will be installed
 --> Processing Dependency: httpd-mmn = 20120211x8664 for package: php-5.4.16-46.el7.x86_64
 Loading mirror speeds from cached hostfile
 base: mirrors.piconets.webwerks.in
 extras: mirrors.piconets.webwerks.in
 updates: mirrors.piconets.webwerks.in
 --> Processing Dependency: php-common(x86-64) = 5.4.16-46.el7 for package: php-5.4.16-46.el7.x86_64
 --> Processing Dependency: php-cli(x86-64) = 5.4.16-46.el7 for package: php-5.4.16-46.el7.x86_64
 --> Processing Dependency: httpd for package: php-5.4.16-46.el7.x86_64
 --> Running transaction check
 ---> Package httpd.x86_64 0:2.4.6-90.el7.centos will be installed
 --> Processing Dependency: httpd-tools = 2.4.6-90.el7.centos for package: httpd-2.4.6-90.el7.centos.x86_64
 --> Processing Dependency: system-logos >= 7.92.1-1 for package: httpd-2.4.6-90.el7.centos.x86_64
 --> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-90.el7.centos.x86_64
 --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-90.el7.centos.x86_64
 --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-90.el7.centos.x86_64
 ---> Package php-cli.x86_64 0:5.4.16-46.el7 will be installed
 ---> Package php-common.x86_64 0:5.4.16-46.el7 will be installed
 --> Processing Dependency: libzip.so.2()(64bit) for package: php-common-5.4.16-46.el7.x86_64
 --> Running transaction check
 ---> Package apr.x86_64 0:1.4.8-5.el7 will be installed
 ---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
 ---> Package centos-logos.noarch 0:70.0.6-3.el7.centos will be installed
 ---> Package httpd-tools.x86_64 0:2.4.6-90.el7.centos will be installed
 ---> Package libzip.x86_64 0:0.10.1-8.el7 will be installed
 ---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
 --> Finished Dependency Resolution 
 Dependencies Resolved
 ========================================================================================================================
  Package                 Arch              Version                           Repository                            Size
 Installing:
  php                     x86_64            5.4.16-46.el7                     /php-5.4.16-46.el7.x86_64            4.4 M
 Installing for dependencies:
  apr                     x86_64            1.4.8-5.el7                       base                                 103 k
  apr-util                x86_64            1.5.2-6.el7                       base                                  92 k
  centos-logos            noarch            70.0.6-3.el7.centos               base                                  21 M
  httpd                   x86_64            2.4.6-90.el7.centos               base                                 2.7 M
  httpd-tools             x86_64            2.4.6-90.el7.centos               base                                  91 k
  libzip                  x86_64            0.10.1-8.el7                      base                                  48 k
  mailcap                 noarch            2.1.41-2.el7                      base                                  31 k
  php-cli                 x86_64            5.4.16-46.el7                     base                                 2.7 M
  php-common              x86_64            5.4.16-46.el7                     base                                 565 k
 Transaction Summary
 Install  1 Package (+9 Dependent packages)
 Total size: 32 M
 Total download size: 28 M
 Installed size: 49 M
 Is this ok [y/d/N]:

Yum package uninstall command

If you want to use the Yum to remove any installed package then instead of using install use remove in the command. In this way:

yum remove package-name

example:

yum remove php-5.4.16-46.el7.x86_64.rpm

Yum command to list all installed RPM packges

If you are comfortable with YUM, you can also use it to see the list of a total number of RPM packages installed on your system, currently.

yum list installed

Moreover, to see the total count of the installed software or packages use:

yum list installed  | wc -l

Use DNF to install RPM packages

Just like a yum package manager, dnf can be used to install RPM software along with the dependencies that particular package requires. It works the same as Yum even the syntax will also be the same, the only difference will be the command starts with dnf instead of yum.

Command structure:

dnf install rpm-package-name

Example: How to use it

dnf install php-5.4.16-46.el7.x86_64.rpm

DNF uninstall command

Just like the YUM, to remove packages with DNF we also use remove instead of install in the syntax.

dnf remove package-name

example:

dnf remove php-5.4.16-46.el7.x86_64.rpm

Bonus Tip:

Yumdownloader

Do you know? We can directly download the RPM package of any software from the official or unofficial repository available on the Linux system using yum downloader command.

Just type the package name you want to download, for example, we want to download the PHP package available in the official repo of CentOS 7, thus the command will be like this:

yumdownloader php

Simple isn’t?

Output of the above commnad:

[root@DESKTOP-9OOKS69 ~]# yumdownloader php
 Loaded plugins: fastestmirror
 Loading mirror speeds from cached hostfile
 base: mirrors.piconets.webwerks.in 
 extras: mirrors.piconets.webwerks.in
 updates: mirrors.piconets.webwerks.in
 base                                | 3.6 kB  00:00:00                                                                                       
 extras                              | 2.9 kB  00:00:00                                                                                        
 updates                             | 2.9 kB  00:00:00                                                                                      
 php-5.4.16-46.el7.x86_64.rpm        | 1.4 MB  00:00:01                                                                

Other Articles :

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.