When you need to download an RPM package and/or its dependencies available on a YUM repo, you can use yumdownloader to either download or obtain the download URLs for the RPM packages. For example, if you have a server in DMZ with YUM broken or without access to the repo then this tip would be very useful to download and copy over to the target server. This will work on RHEL/CentOS 5,6 and 7
“yumdownloader” is provided by the “yum-utils” package. If you do not already have the package installed. Install as follows:
[root@c7vanilla ~]# yum install yum-utils -y
Now, to obtain the URL for a package (say mariadb)
[root@c7vanilla ~]# yumdownloader --urls mariadb|egrep -v " " http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/mariadb-5.5.44-2.el7.centos.x86_64.rpm
You can also use repoquery to provide the package URL
[root@c7vanilla ~]# repoquery --location mariadb http://mirror.vorboss.net/centos/7.2.1511/os/x86_64/Packages/mariadb-5.5.44-2.el7.centos.x86_64.rpm
To obtain the URL for “mariadb” and all its dependency packages
[root@c7vanilla ~]# yumdownloader --resolve --urls mariadb|egrep -v " " http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/mariadb-5.5.44-2.el7.centos.x86_64.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-HTTP-Tiny-0.033-3.el7.noarch.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-threads-shared-1.43-6.el7.x86_64.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Storable-2.45-3.el7.x86_64.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Exporter-5.68-3.el7.noarch.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-constant-1.27-2.el7.noarch.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-PathTools-3.40-5.el7.x86_64.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-libs-5.16.3-286.el7.x86_64.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-macros-5.16.3-286.el7.x86_64.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-parent-0.225-244.el7.noarch.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-5.16.3-286.el7.x86_64.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-File-Temp-0.23.01-3.el7.noarch.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Pod-Simple-3.28-4.el7.noarch.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Time-Local-1.2300-2.el7.noarch.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Pod-Perldoc-3.20-4.el7.noarch.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Socket-2.010-3.el7.x86_64.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Carp-1.26-244.el7.noarch.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Time-HiRes-1.9725-3.el7.x86_64.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Scalar-List-Utils-1.27-248.el7.x86_64.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Pod-Escapes-1.04-286.el7.noarch.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Pod-Usage-1.63-3.el7.noarch.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Enpre-2.51-7.el7.x86_64.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-podlators-2.5.1-3.el7.noarch.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Getopt-Long-2.40-2.el7.noarch.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-File-Path-2.09-2.el7.noarch.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-threads-1.87-4.el7.x86_64.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Filter-1.49-3.el7.x86_64.rpm http://mirror.sov.uk.goscomb.net/centos/7.2.1511/os/x86_64/Packages/perl-Text-ParseWords-3.29-4.el7.noarch.rpm
To download the package only
[root@c7vanilla ~]# yumdownloader --destdir=/var/tmp/ mariadb Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.sov.uk.goscomb.net * extras: mirrors.vooservers.com * updates: mirrors.vooservers.com mariadb-5.5.44-2.el7.centos.x86_64.rpm | 8.9 MB 00:00:17
NOTE: If you didn’t specify “–destdir=”, yumdownloader defaults to the current working directory
To download the package and its dependencies
[root@c7vanilla ~]# yumdownloader --destdir=/var/tmp/ mariadb (1/27): perl-File-Path-2.09-2.el7.noarch.rpm | 26 kB 00:00:00 (2/27): perl-Exporter-5.68-3.el7.noarch.rpm | 28 kB 00:00:00 (3/27): perl-Carp-1.26-244.el7.noarch.rpm | 19 kB 00:00:00 (4/27): perl-Getopt-Long-2.40-2.el7.noarch.rpm | 56 kB 00:00:00 (5/27): perl-Filter-1.49-3.el7.x86_64.rpm | 76 kB 00:00:00 (6/27): perl-File-Temp-0.23.01-3.el7.noarch.rpm | 56 kB 00:00:00 (7/27): perl-HTTP-Tiny-0.033-3.el7.noarch.rpm | 38 kB 00:00:00 (8/27): perl-Pod-Escapes-1.04-286.el7.noarch.rpm | 50 kB 00:00:00 (9/27): perl-PathTools-3.40-5.el7.x86_64.rpm | 82 kB 00:00:00 (10/27): perl-Pod-Perldoc-3.20-4.el7.noarch.rpm | 87 kB 00:00:00 (11/27): perl-Scalar-List-Utils-1.27-248.el7.x86_64.rpm | 36 kB 00:00:00 (12/27): perl-Socket-2.010-3.el7.x86_64.rpm | 49 kB 00:00:00 (13/27): perl-Pod-Usage-1.63-3.el7.noarch.rpm | 27 kB 00:00:01 (14/27): perl-Storable-2.45-3.el7.x86_64.rpm | 77 kB 00:00:00 (15/27): perl-Pod-Simple-3.28-4.el7.noarch.rpm | 216 kB 00:00:01 (16/27): perl-Time-HiRes-1.9725-3.el7.x86_64.rpm | 45 kB 00:00:00 (17/27): perl-Time-Local-1.2300-2.el7.noarch.rpm | 24 kB 00:00:00 (18/27): perl-Text-ParseWords-3.29-4.el7.noarch.rpm | 14 kB 00:00:00 (19/27): perl-constant-1.27-2.el7.noarch.rpm | 19 kB 00:00:00 (20/27): perl-parent-0.225-244.el7.noarch.rpm | 12 kB 00:00:00 (21/27): perl-podlators-2.5.1-3.el7.noarch.rpm | 112 kB 00:00:00 (22/27): perl-macros-5.16.3-286.el7.x86_64.rpm | 43 kB 00:00:00 (23/27): perl-threads-1.87-4.el7.x86_64.rpm | 49 kB 00:00:00 (24/27): perl-threads-shared-1.43-6.el7.x86_64.rpm | 39 kB 00:00:00 (25/27): perl-libs-5.16.3-286.el7.x86_64.rpm | 687 kB 00:00:03 (26/27): perl-Enpre-2.51-7.el7.x86_64.rpm | 1.5 MB 00:00:08 (27/27): perl-5.16.3-286.el7.x86_64.rpm | 8.0 MB 00:00:18