Print Friendly, PDF & Email
By modifying the yum configuration file, you can instruct the yum to save downloaded RPM packages to any local directory.
GOAL

To enable package caching so that the package files downloaded by yum stay in cache directory.

RELATED

HOW TO CREATE A LOCAL YUM REPOSITORY CONTAINING MANUALLY DOWNLOADED RPM PACKAGES

SOLUTION

To configure yum to retain downloaded files rather than discarding them, set the keepcache option in /etc/yum.conf to 1.
To change the location of yum cache from the default, adjust the cachedir option in /etc/yum.conf as needed.

DEMO

Get current yum configuration details

[root@dbpilot ~] cat /etc/yum.conf |grep -v "#"
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3

Create a new directory for storing cached packages

[root@dbpilot ~] mkdir /tmp/cachedRPM

Edit the cachedir and the keepcache parameters

[root@dbpilot ~] cat /etc/yum.conf |grep -v "#"
[main]
cachedir=/tmp/cachedRPM
keepcache=1
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3

Install required packages. For instance, vim and mlocate

[root@dbpilot ~]  ls -l /tmp/cachedRPM
total 0

[root@dbpilot ~] yum install vim-enhanced mlocate -y

Confirm that yum cached packages in the custom directory after successful installation

[root@dbpilot ~] rpm -qa |egrep "vim-enhanced|mlocate"
vim-enhanced-7.4.160-1.el7.x86_64
mlocate-0.26-6.el7.x86_64

[root@dbpilot ~] ls /tmp/cachedRPM
mlocate-0.26-6.el7.x86_64.rpm  vim-enhanced-7.4.160-1.el7.x86_64.rpm

Written At
05 FEB 201814:00
Red Hat Release
7.3 x64