How to Download RPM Package Including Dependencies in Red Hat or CentOS

There are times when we want to install packages on rpm derivative Servers which have restricted or no access to internet. What do we do in this case?  How to download RPM Packages including their dependencies?


Method 1 – Download AN RPM Package With All Dependencies Using “Downloadonly” plugin

We can use the yum-plugin-downloadonly  utility to download a package along with its dependencies.


To install Downloadonly plugin, run the following command as root user.
yum install -y yum-plugin-downloadonly

Once the plugin is installed, we can download the package using following command:

yum install --downloadonly <package-name>

By default, this command will download and save the packages in /var/cache/yum/ in rhel-{arch}-channel/packages location. However, you can download and save the packages in any location of your choice using “--downloaddir” option.

yum install --downloadonly --downloaddir=<directory> <package-name

Method 2 – Download RPM Package including Dependencies with yumdownloader


Another method to download and install packages along with its dependencies is using the yumdownloader command. In order to install the package issue the following command as a root user or sudo user:

yum install -y yum-utils


Once the package is installed, run the following command to download the package:

yumdownloader <package name>


We can also force the package to resolve it’s dependencies using the following flag:

yumdownloader --resolve <package name>


Additionally, package files can be downloaded to custom location by using the --destdir flag:

yumdownloader --resolve --destdir<package name>


Sample output


[root@server ~]# yumdownloader --resolve --destdir=./custom_package/ httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * epel:
 * extras:
 * updates:
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-60.el6.centos.6 will be installed
--> Processing Dependency: httpd-tools = 2.2.15-60.el6.centos.6 for package: httpd-2.2.15-60.el6.centos.6.x86_64
--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-60.el6.centos.6.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.2.15-60.el6.centos.6.x86_64
--> Processing Dependency: for package: httpd-2.2.15-60.el6.centos.6.x86_64
--> Processing Dependency: for package: httpd-2.2.15-60.el6.centos.6.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.3.9-5.el6_9.1 will be installed
---> Package apr-util.x86_64 0:1.3.9-3.el6_0.1 will be installed
---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be installed
---> Package httpd-tools.x86_64 0:2.2.15-60.el6.centos.6 will be installed
---> Package mailcap.noarch 0:2.1.31-2.el6 will be installed
--> Finished Dependency Resolution
httpd-2.2.15-60.el6.centos.6.x86_64.rpm | 836 kB 00:00
httpd-tools-2.2.15-60.el6.centos.6.x86_64.rpm | 80 kB 00:00
apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm | 15 kB 00:00
apr-1.3.9-5.el6_9.1.x86_64.rpm | 124 kB 00:00
mailcap-2.1.31-2.el6.noarch.rpm | 27 kB 00:00
apr-util-1.3.9-3.el6_0.1.x86_64.rpm | 87 kB 00:00
[root@server ~]#
[root@server ~]# ll custom_package/
total 1180
-rw-r--r--. 1 root root 126508 Nov 28 22:08 apr-1.3.9-5.el6_9.1.x86_64.rpm
-rw-r--r--. 1 root root 89340 Jul 6 2011 apr-util-1.3.9-3.el6_0.1.x86_64.rpm
-rw-r--r--. 1 root root 15824 Jul 6 2011 apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm
-rw-r--r--. 1 root root 856156 Oct 20 17:13 httpd-2.2.15-60.el6.centos.6.x86_64.rpm
-rw-r--r--. 1 root root 82248 Oct 20 17:13 httpd-tools-2.2.15-60.el6.centos.6.x86_64.rpm
-rw-r--r--. 1 root root 27280 Sep 26 2011 mailcap-2.1.31-2.el6.noarch.rpm


I hope this has been informative for you. I am pretty sure that in Production environment where there are multiple restricted servers, this task of how to download RPM package including dependencies would have lead you to scratch your head couple times.

Share your thoughts