How to use yum locally without internet connection using cache?

yum is an short abbreviation for Yellowdog Updater Modified
 

What is yum?

yum  is  an  interactive, rpm based, package manager. It can automatically perform system updates, including dependency analysis and obsolete processing based on "repository" metadata. It can also perform installation of  new  packages,  removal  of  old packages and perform queries on the installed and/or available packages among many other commands/services.
 

How to use yum without internet connection?

By default, yum deletes downloaded data files when they are no longer needed after a successful operation. This minimizes the amount of storage space that yum uses.However, you can enable caching, so that the package files downloaded by yum stay in cache directories. By using cached data, you can carry out certain operations without a network connection, you can also copy packages stored in the caches and reuse them elsewhere
 

 

yum stores temporary files in the /var/cache/yum/$basearch/$releasever/directory, where $basearch and $releasever are Yum variables refering to base architecture of the system and the release version of Red Hat Enterprise Linux.

You can find the values for the $basearch and $releasever variables in the output of the yum version command.

# yum version
Loaded plugins: fastestmirror, refresh-packagekit, security
Warning: RPMDB altered outside of yum.
Installed: 6/i386                  1143:95f0fe20d81af24850e6364a81367b66c9f4a1e2
Group-Installed: yum                 14:3224f04a082a6cc0af5bc42667a6c5315ca35e96
version

 

Enabling the Caches

To retain the cache of packages after a successful installation, add the following text to the [main] section of /etc/yum.conf.
keepcache = 1 Once you enabled caching, every yum operation may download package data from the configured repositories.
To download and make usable all the metadata for the currently enabled yum repositories, type:

# yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.ispros.com.bd
 * extras: mirror.digistar.vn
 * updates: mirror.vietoss.com
base                                                     | 3.7 kB     00:00
base/group_gz                                            | 214 kB     00:11
base/filelists_db                                        | 5.1 MB     07:31
base/primary_db                                          | 3.6 MB     08:58
base/other_db                                            | 2.2 MB     05:25
extras                                                   | 3.3 kB     00:00
extras/filelists_db                                      |  31 kB     00:00
extras/prestodelta                                       |   78 B     00:00
extras/primary_db                                        |  28 kB     00:00
extras/other_db                                          |  35 kB     00:01
updates                                                  | 3.4 kB     00:00
updates/filelists_db                                     | 614 kB     00:08
updates/prestodelta                                      |  58 kB     00:00
updates/primary_db                                       | 800 kB     00:10
updates/other_db                                         | 6.0 MB     00:58
Metadata Cache Created

This is useful if you want to make sure that the cache is fully up to date with all metadata. To set the time after which the metadata will expire, use the metadata-expire setting in /etc/yum.conf.
From man page
makecache: Is used to download and make usable all the metadata for the currently enabled yum repos.
 

Using yum in Cache-only Mode

To carry out a yum command without a network connection, add the -C command-line option. With this option, yum proceeds without checking any network repositories, and uses only cached files. In this mode, yum may only install packages that have been downloaded and cached by a previous operation.
# yum -C list glibc
Loaded plugins: fastestmirror, refresh-packagekit, security
Installed Packages
glibc.i686                         2.12-1.132.el6                          @base
Available Packages
glibc.i686                         2.12-1.149.el6                          base

So as you see we have an update for glibc package which we can install with out internet connection using the cache by using the below command

# yum -C update glibc

 

Clearing the yum Caches

It is often useful to remove entries accumulated in the /var/cache/yum/ directory. If you remove a package from the cache, you do not affect the copy of the software installed on your system. To remove all entries for currently enabled repositories from the cache, type the following as a root:

# yum clean all

I hope the tutorial was helpful.