How to (temporarily) prevent yum / dnf from updating repositories

dnf

I sometimes face a problem that I only want to search or install a single tiny package and I am on a very limited internet connection (say: mobile data in a remote place abroad). Being more of an emergency case, I wouldn't mind using the cached repository contents; the last update would have been just a week or two ago. Yet dnf insists on downloading several MB of metadata which takes forever and which I don't want, and earlier today it happened that I was just rendered unable to finish a simple search operation due to this. I tried running the command offline but it refuses to operate if the metadata is not current. Is there an option forcing the command to use the old data, or a configuration entry to change the period for how long it is considered valid?

Best Answer

If you look in the various dnf and yum repo config files you should find several explicit metadata expiry times, eg:

/etc/yum.repos.d/fedora-updates.repo
  metadata_expire=6h

/etc/dnf/dnf.conf
  metadata_expire=86400

You can override these on the dnf command line using --setopt=, but you must explicitly do it for every enabled repository, as well as the dnf main configuration. So you end up with something like

sudo dnf --setopt=metadata_expire=-1 \
 --setopt=fedora.metadata_expire=-1 \
 --setopt=fedora-update.metadata_expire=-1 \
 --setopt=rpmfusion-free.metadata_expire=-1 \
 search abcdef

Note the use of sudo to avoid dnf creating a separate cache for the user.

Related Question