How to download RPM packages

Download RPM packages from YUM repository using additional yum utilities.

Installation

I will use yumdownloader which is provided by yum-utils package.

$ yum whatprovides --cacheonly  yumdownloader
Loaded plugins: fastestmirror
yum-utils-1.1.31-50.el7.noarch : Utilities based around the yum package manager
Repo        : base
Matched from:
Filename    : /usr/bin/yumdownloader



yum-utils-1.1.31-50.el7.noarch : Utilities based around the yum package manager
Repo        : @anaconda
Matched from:
Filename    : /usr/bin/yumdownloader



As you can see it was installed during OS installation, but you can always install it later.

$ sudo yum install yum-utils

Usage

List package URLs for ansible.

$ yumdownloader --cacheonly --urls ansible
Loaded plugins: fastestmirror
http://ftp.man.poznan.pl/pub/centos/7.6.1810/extras/x86_64/Packages/ansible-2.4.2.0-2.el7.noarch.rpm

Download memtest86+ package.

$ yumdownloader --cacheonly memtest86+
Loaded plugins: fastestmirror
memtest86+-5.01-2.el7.x86_64.rpm
$ ls -l memtest86+-5.01-2.el7.x86_64.rpm 
-rw-rw-r--. 1 milosz milosz 84820 Nov 20  2016 memtest86+-5.01-2.el7.x86_64.rpm

Download powertop package to /home/milosz/powertop directory.

$ yumdownloader --cacheonly --destdir /home/milosz/powertop powertop
Loaded plugins: fastestmirror
powertop-2.9-1.el7.x86_64.rpm  
$ ls -l /home/milosz/powertop/
total 220
-rw-rw-r--. 1 milosz milosz 225168 Nov 12  2018 powertop-2.9-1.el7.x86_64.rpm

Download bind package including its dependencies to /home/milosz/bind directory.

$ yumdownloader --cacheonly --resolve --destdir /home/milosz/bind bind
Loaded plugins: fastestmirror
--> Running transaction check
---> Package bind.x86_64 32:9.9.4-74.el7_6.1 will be installed
--> Processing Dependency: bind-libs = 32:9.9.4-74.el7_6.1 for package: 32:bind-9.9.4-74.el7_6.1.x86_64
--> Processing Dependency: python-ply for package: 32:bind-9.9.4-74.el7_6.1.x86_64
--> Processing Dependency: policycoreutils-python for package: 32:bind-9.9.4-74.el7_6.1.x86_64
--> Processing Dependency: policycoreutils-python for package: 32:bind-9.9.4-74.el7_6.1.x86_64
--> Processing Dependency: liblwres.so.90()(64bit) for package: 32:bind-9.9.4-74.el7_6.1.x86_64
--> Processing Dependency: libisccfg.so.90()(64bit) for package: 32:bind-9.9.4-74.el7_6.1.x86_64
--> Processing Dependency: libisccc.so.90()(64bit) for package: 32:bind-9.9.4-74.el7_6.1.x86_64
--> Processing Dependency: libisc.so.95()(64bit) for package: 32:bind-9.9.4-74.el7_6.1.x86_64
--> Processing Dependency: libdns.so.100()(64bit) for package: 32:bind-9.9.4-74.el7_6.1.x86_64
--> Processing Dependency: libbind9.so.90()(64bit) for package: 32:bind-9.9.4-74.el7_6.1.x86_64
--> Running transaction check
---> Package bind-libs.x86_64 32:9.9.4-74.el7_6.1 will be installed
---> Package policycoreutils-python.x86_64 0:2.5-29.el7_6.1 will be installed
--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libsemanage-python >= 2.5-14 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libcgroup for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
---> Package python-ply.noarch 0:3.4-11.el7 will be installed
--> Running transaction check
---> Package audit-libs-python.x86_64 0:2.8.4-4.el7 will be installed
---> Package checkpolicy.x86_64 0:2.5-8.el7 will be installed
---> Package libcgroup.x86_64 0:0.41-20.el7 will be installed
---> Package libsemanage-python.x86_64 0:2.5-14.el7 will be installed
---> Package python-IPy.noarch 0:0.75-6.el7 will be installed
---> Package setools-libs.x86_64 0:3.3.8-4.el7 will be installed
--> Finished Dependency Resolution
(1/10): audit-libs-python-2.8.4-4.el7.x86_64.rpm                                                                  |  76 kB  00:00:00
(2/10): libcgroup-0.41-20.el7.x86_64.rpm                                                                          |  66 kB  00:00:00
(3/10): libsemanage-python-2.5-14.el7.x86_64.rpm                                                                  | 113 kB  00:00:00
(4/10): python-IPy-0.75-6.el7.noarch.rpm                                                                          |  32 kB  00:00:00
(5/10): checkpolicy-2.5-8.el7.x86_64.rpm                                                                          | 295 kB  00:00:00
(6/10): policycoreutils-python-2.5-29.el7_6.1.x86_64.rpm                                                          | 456 kB  00:00:00
(7/10): python-ply-3.4-11.el7.noarch.rpm                                                                          | 123 kB  00:00:00
(8/10): bind-9.9.4-74.el7_6.1.x86_64.rpm                                                                          | 1.8 MB  00:00:01
(9/10): setools-libs-3.3.8-4.el7.x86_64.rpm                                                                       | 620 kB  00:00:00
(10/10): bind-libs-9.9.4-74.el7_6.1.x86_64.rpm                                                                    | 1.0 MB  00:00:01
$ ls -l /home/milosz/bind/
total 4724
-rw-rw-r--. 1 milosz milosz   78216 Nov 12  2018 audit-libs-python-2.8.4-4.el7.x86_64.rpm
-rw-rw-r--. 1 milosz milosz 1927932 Jun 10 10:19 bind-9.9.4-74.el7_6.1.x86_64.rpm
-rw-rw-r--. 1 milosz milosz 1062260 Jun 10 10:19 bind-libs-9.9.4-74.el7_6.1.x86_64.rpm
-rw-rw-r--. 1 milosz milosz  302068 Nov 12  2018 checkpolicy-2.5-8.el7.x86_64.rpm
-rw-rw-r--. 1 milosz milosz   67652 Nov 12  2018 libcgroup-0.41-20.el7.x86_64.rpm
-rw-rw-r--. 1 milosz milosz  115284 Nov 12  2018 libsemanage-python-2.5-14.el7.x86_64.rpm
-rw-rw-r--. 1 milosz milosz  466748 Feb  1 16:22 policycoreutils-python-2.5-29.el7_6.1.x86_64.rpm
-rw-rw-r--. 1 milosz milosz   32880 Jul  4  2014 python-IPy-0.75-6.el7.noarch.rpm
-rw-rw-r--. 1 milosz milosz  125732 Aug 10  2017 python-ply-3.4-11.el7.noarch.rpm
-rw-rw-r--. 1 milosz milosz  635184 Nov 12  2018 setools-libs-3.3.8-4.el7.x86_64.rpm

Simple as that.