How To Download a RPM Package Using yum Command Without Installing On Linux

If you ever wanted to download the rpm package instead of installing it with yum ! you can do that with ease, that is useful when you want to keep backup of some RPMs or want to see what’s inside RPM etc.

So how to download a RPM package using yum command under CentOS, Enterprise Linux server 5.x or RHEL 5.x systems (any yum supported) ?

First you need to install plugin called “yum-downloadonly”. After installing the plugin you can use  –downloadonly flag to yum so that yum will only download the packages and will not install/update them. Following options supported by this plugin:

1[a] --downloadonly : don't update, just download a rpm file
2[b] --downloaddir=/path/to/dir : specifies an alternate directory to store packages such as /tmp

Please note following instructions are only tested on CentOS server but should work with Fedora, RHN and RHEL without any problem.

To install yum-downloadonly plugin:-

Type the following command to install plugin, enter:

1# yum install yum-downloadonly

Sample output:

01Loading "fastestmirror" plugin
02Loading "security" plugin
03Loading mirror speeds from cached hostfile
04* base: centos.mirrors.tds.net
05* updates: mirror.myriadnetwork.com
06* addons: mirrors.gigenet.com
07* extras: holmes.umflint.edu
08Setting up Install Process
09Parsing package install arguments
10Resolving Dependencies
11--> Running transaction check
12---> Package yum-downloadonly.noarch 0:1.1.10-9.el5.centos set to be updated
13--> Finished Dependency Resolution
14Dependencies Resolved
15=============================================================================
16Package Arch Version Repository Size
17=============================================================================
18Installing:
19yum-downloadonly noarch 1.1.10-9.el5.centos base 9.0 k
20Transaction Summary
21=============================================================================
22Install 1 Package(s)
23Update 0 Package(s)
24Remove 0 Package(s)
25Total download size: 9.0 k
26Is this ok [y/N]: y
27Downloading Packages:
28(1/1): yum-downloadonly-1 100% |=========================| 9.0 kB 00:00
29Running rpm_check_debug
30Running Transaction Test
31Finished Transaction Test
32Transaction Test Succeeded
33Running Transaction
34Installing: yum-downloadonly ######################### [1/1]
35Installed: yum-downloadonly.noarch 0:1.1.10-9.el5.centos
36Complete!

How do I download a RPM package only from RHN or CentOS mirror, without installing it?

Download httpd package but don’t install/update, enter:

1# yum update httpd -y --downloadonly

By default package will by downloaded and stored in /var/cache/yum/ directory. But, you can specifies an alternate directory to store packages such as /opt, enter:

1# yum update httpd -y --downloadonly --downloaddir=/opt

Sample output:

01yum install httpd -y --downloadonly
02Loading "downloadonly" plugin
03Loading "fastestmirror" plugin
04Loading "security" plugin
05Loading mirror speeds from cached hostfile
06* base: centos.mirrors.mypsh.com
07* updates: mirror.steadfast.net
08* addons: mirrors.gigenet.com
09* extras: holmes.umflint.edu
10Setting up Install Process
11Parsing package install arguments
12Resolving Dependencies
13--> Running transaction check
14---> Package httpd.i386 0:2.2.3-11.el5_1.centos.3 set to be updated
15filelists.xml.gz 100% |=========================| 2.8 MB 00:03
16filelists.xml.gz 100% |=========================| 681 kB 00:11
17filelists.xml.gz 100% |=========================| 122 kB 00:00
18filelists.xml.gz 100% |=========================| 150 B 00:00
19--> Finished Dependency Resolution
20Dependencies Resolved
21=============================================================================
22Package Arch Version Repository Size
23=============================================================================
24Installing:
25httpd i386 2.2.3-11.el5_1.centos.3 base 1.1 M
26Transaction Summary
27=============================================================================
28Install 1 Package(s)
29Update 0 Package(s)
30Remove 0 Package(s)
31Total download size: 1.1 M
32Downloading Packages:
33(1/1): httpd-2.2.3-11.el5 100% |=========================| 1.1 MB 00:01
34exiting because --downloadonly specified

To see downloaded file, enter:

1# ls -l /opt/*.rpm

Sample output:

1-rw-r--r-- 1 root root 1116426 Jan 17 03:36 /opt/httpd-2.2.3-11.el5_1.centos.3.i386.rpm
2-rw-r--r-- 1 root root 83452 Oct 2 2007 /opt/lighttpd-fastcgi-1.4.18-1.el5.rf.i386.rpm
3-rw-r--r-- 1 root root 635045 Oct 20 2007 /opt/psad-2.1-1.i386.rpm

Method # 2: yum-utils.noarch Package

yum-utils is a collection of utilities and examples for the yum package manager. It includes utilities by different authors that make yum easier and more powerful to use. These tools include: debuginfo-install, package-cleanup, repoclosure, repodiff, repo-graph, repomanage, repoquery, repo-rss, reposync, repotrack, verifytree, yum-builddep, yum-complete-transaction, yumdownloader, yum-debug-dump and yum-groups-manager.

1# yum -y install yum-utils.noarch

Now use the yumdownloader command which is a program for downloading RPMs from Yum repositories. Type the following command to download httpd rpm file:

1# yumdownloader httpd

Sample outputs:

1Loaded plugins: rhnplugin
2httpd-2.2.3-31.el5_4.2.x86_64.rpm | 1.2 MB 00:00

How Do I Extract Downloaded RPM File?

Type the command as follows:

1# rpm2cpio httpd-2.2.3-31.el5_4.2.x86_64.rpm | cpio -idmv