How To Install An RPM File In Linux

RPM files exist to make the software installation and upgrading process easier. They allow us to simply use an RPM file to install a software package, and when combined with package managers such as Yum or DNF we will also get all required dependencies downloaded and installed easily.

Not all distributions of Linux support RPM. Generally RPM files are used in RHEL based distributions such as CentOS and Fedora to name a couple, however it has also been ported elsewhere. If you find that your distribution does not support installing an RPM file, you may need to look at other options such as .deb files in Ubuntu/Debian.

If you’ve downloaded an RPM file from the Internet, there are a couple of tools you can use to install it. Personally I prefer to use Yum/DNF, these act like a front-end to the RPM command and will maintain an up to date database of package dependencies.

Install RPM File With Yum

Normally when installing a package from a repository with the yum command, you would run ‘yum install httpd’ and it will simply download the required RPM file from a configured repository. We can instead use ‘yum install file.rpm’ and specify a local RPM file that we have to install.

[root@centos7 ~]# yum instsall httpd-2.4.6-45.el7.centos.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Examining httpd-2.4.6-45.el7.centos.x86_64.rpm: httpd-2.4.6-45.el7.centos.x86_64
Marking httpd-2.4.6-45.el7.centos.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-45.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-45.el7.centos for package: httpd-2.4.6-45.el7.centos.x86_64
Loading mirror speeds from cached hostfile
 * base: centos.mirror.serversaustralia.com.au
 * extras: ftp.swin.edu.au
 * updates: centos.mirror.serversaustralia.com.au
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-45.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-45.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-45.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-45.el7.centos 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:
 httpd           x86_64     2.4.6-45.el7.centos        /httpd-2.4.6-45.el7.centos.x86_64     9.4 M
Installing for dependencies:
 apr             x86_64     1.4.8-3.el7                base                                  103 k
 apr-util        x86_64     1.5.2-6.el7                base                                   92 k
 httpd-tools     x86_64     2.4.6-45.el7.centos        base                                   84 k
 mailcap         noarch     2.1.41-2.el7               base                                   31 k

Transaction Summary
===================================================================================================
Install  1 Package (+4 Dependent packages)

Total size: 9.7 M
Total download size: 309 k
Installed size: 10 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): apr-1.4.8-3.el7.x86_64.rpm                              | 103 kB  00:00:00
(2/4): mailcap-2.1.41-2.el7.noarch.rpm                         |  31 kB  00:00:00
(3/4): httpd-tools-2.4.6-45.el7.centos.x86_64.rpm              |  84 kB  00:00:00
(4/4): apr-util-1.5.2-6.el7.x86_64.rpm                         |  92 kB  00:00:00
---------------------------------------------------------------------------------
Total                                                 247 kB/s | 309 kB  00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-3.el7.x86_64                           1/5
  Installing : apr-util-1.5.2-6.el7.x86_64                      2/5
  Installing : httpd-tools-2.4.6-45.el7.centos.x86_64           3/5
  Installing : mailcap-2.1.41-2.el7.noarch                      4/5
  Installing : httpd-2.4.6-45.el7.centos.x86_64                 5/5
  Verifying  : httpd-tools-2.4.6-45.el7.centos.x86_64           1/5
  Verifying  : mailcap-2.1.41-2.el7.noarch                      2/5
  Verifying  : httpd-2.4.6-45.el7.centos.x86_64                 3/5
  Verifying  : apr-util-1.5.2-6.el7.x86_64                      4/5
  Verifying  : apr-1.4.8-3.el7.x86_64                           5/5

Installed:
  httpd.x86_64 0:2.4.6-45.el7.centos

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7                          apr-util.x86_64 0:1.5.2-6.el7
  httpd-tools.x86_64 0:2.4.6-45.el7.centos          mailcap.noarch 0:2.1.41-2.el7

Complete!

We can also use ‘yum localinstall file.rpm’, however the man page notes that this is maintained for legacy reasons only and suggests using install instead.

Not only is the httpd RPM file that we specified installed, but so are the listed additional dependencies that the httpd package needs to work properly.

Note that unlike the RPM command covered later, yum automatically resolves the dependencies for us and will download and install any additional packages from our configured repositories.

If you’d like further information on using yum, see our 25 yum command examples here.

Install RPM File With DNF

DNF is the next version of Yum, it’s another package manager for working with RPM files. DNF syntax is fairly similar to the Yum command, as shown below we can install our RPM file in the same way.

[root@centos7 ~]# dnf install httpd-2.4.6-45.el7.centos.x86_64.rpm
Extra Packages for Enterprise Linux 7 - x86_64                     9.7 MB/s |  12 MB     00:01
Using metadata from Thu Dec 29 21:31:01 2016
Dependencies resolved.
===================================================================================================
 Package           Arch              Version                         Repository               Size
===================================================================================================
Installing:
 httpd             x86_64            2.4.6-45.el7.centos             @commandline            2.7 M

Transaction Summary
===================================================================================================
Install  1 Package

Total size: 2.7 M
Is this ok [y/N]:

As of Fedora 22 DNF has replaced Yum, so that’s useful to be aware of although it has not yet made its way into RHEL/CentOS where Yum is still the king.

If you’d like further information on using dnf, see our 25 dnf command examples here.

Install RPM File With RPM Command

For comparison, we can also use the rpm command with the -i option to install a specified RPM package. This is not however capable of automatically resolving the dependencies for us, as shown by the errors below we would have to go out and manually download these additional packages, which then themselves may have further package dependencies. This situation is commonly referred to as dependency hell, and is something package managers help us avoid.

[root@centos7 ~]# rpm -i httpd-2.4.6-45.el7.centos.x86_64.rpm
error: Failed dependencies:
        /etc/mime.types is needed by httpd-2.4.6-45.el7.centos.x86_64
        httpd-tools = 2.4.6-45.el7.centos is needed by httpd-2.4.6-45.el7.centos.x86_64
        libapr-1.so.0()(64bit) is needed by httpd-2.4.6-45.el7.centos.x86_64
        libaprutil-1.so.0()(64bit) is needed by httpd-2.4.6-45.el7.centos.x86_64

How To Download RPM Files

Usually RPM files will be downloaded from some random page on the Internet, however it’s possible to also download an RPM file from a repository directly using the yumdownloader command. Simply specify the package that you want to download after yumdownloader and it will download a copy of the RPM file that is used to install the package into the current working directory.

[root@centos7 ~]# yumdownloader httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.mirror.serversaustralia.com.au
 * extras: ftp.swin.edu.au
 * updates: centos.mirror.serversaustralia.com.au
httpd-2.4.6-45.el7.centos.x86_64.rpm                                        | 2.7 MB  00:00:00

[root@centos7 ~]# ls -la httpd-2.4.6-45.el7.centos.x86_64.rpm
-rw-r--r--. 1 root root 2827204 Nov 20 10:14 httpd-2.4.6-45.el7.centos.x86_64.rpm

This can be a useful way to quickly download a RPM package file using yum to copy elsewhere, perhaps to a Linux server that is in an isolated network without Internet access for example.

Summary

We have covered three different methods for installing RPM files in Linux here. While using Yum/DNF are the preferred options for the reasons mentioned such as automatic dependency resolution, we can also use the rpm command with the -i option to install an RPM file in supported Linux distributions.

  1. Thank you very much you are a good man

  2. Thank you for explanation. I have a question: does exist a command or a way to install an .rpm and automatically install dependencies-files at one time?

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>