How to Force YUM to Install Packages Without Updating Repository Metadata


2 views

Every RHEL/CentOS/Fedora admin has faced this scenario: you just want to quickly install a package, but yum insists on updating its repository metadata first. This happens even with the -C flag when the cache is present but deemed stale.

# What you expect to be fast:
sudo yum install nginx -y

# What actually happens:
Metadata refresh spanning several minutes
Downloading 4.7MB of package lists
Verifying repository mirrors...

While not recommended for production, this brute-force approach works:

sudo yum install --nogpgcheck --disablerepo=* package-name

This tells YUM to:
1. Skip GPG verification (security risk)
2. Disable all repositories (then re-enables them automatically)
3. Use whatever cached metadata exists

The correct way is to modify YUM's metadata expiration settings in /etc/yum.conf:

[main]
metadata_expire=86400  # 24 hours in seconds

Or for a one-time override:

sudo yum --metadata-expire=60 install package

YUM maintains cache at /var/cache/yum. Force using existing cache with:

sudo yum -C --cacheonly install package

If you get "Cache not found", first populate it with:

sudo yum makecache fast

In automated environments where speed matters more than absolute package freshness:

# Pipeline YUM installation script
YUM_OPTS="--setopt=metadata_expire=300 --quiet --assumeyes"
sudo yum $YUM_OPTS install docker-ce

This configuration:
- Sets metadata to expire every 5 minutes
- Runs non-interactively
- Suppresses non-error output


Many Linux system administrators encounter this frustrating scenario: you just want to quickly install a package using yum install, but YUM insists on updating repository metadata first. This behavior can be particularly annoying when:

  • Working on slow network connections
  • Managing multiple servers where repository consistency is already verified
  • Needing to perform quick installations in automated scripts

YUM's default behavior of updating repository metadata serves an important purpose - it ensures you're installing the latest available versions of packages and their dependencies. However, there are legitimate cases where you want to bypass this:

# Typical yum install output showing metadata updates
$ yum install nginx
Loaded plugins: fastestmirror
Determining fastest mirrors
updates/metalink | 23 kB 00:00
* base: mirror.rackspace.com
* updates: mirror.rackspace.com
base | 3.6 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 4.6 MB 01:23

Here are several methods to install packages without repository updates:

Method 1: Using --nogpgcheck and -C Flags

yum install --nogpgcheck -C package-name

The -C flag tells YUM to use the cache only, while --nogpgcheck skips package verification (use with caution).

Method 2: Setting metadata_expire in yum.conf

Edit /etc/yum.conf:

[main]
metadata_expire=never

This makes YUM treat metadata as never expired, though it's not recommended for production systems.

Method 3: Using dnf (Fedora's YUM replacement)

dnf --cacheonly install package-name

DNF offers more explicit control over caching behavior.

Be cautious when skipping metadata updates. You might encounter:

  • Missing dependencies if repository contents changed
  • Version conflicts with existing packages
  • Security risks from outdated package information

For environments where network latency is a constant issue:

# Create local repository
mkdir /local/repo
createrepo /local/repo

# Add to yum.repos.d
cat > /etc/yum.repos.d/local.repo << EOF
[local]
name=Local Repository
baseurl=file:///local/repo
enabled=1
gpgcheck=0
EOF

While skipping metadata updates can save time, it's generally safer to let YUM perform its normal checks. Reserve these techniques for:

  • Emergency situations with network constraints
  • Controlled environments where repository consistency is guaranteed
  • Temporary workarounds when repository servers are unavailable