Table of Contents#
- Understanding Yum Repository Metadata
- Why Disable Frequent Metadata Updates?
- Methods to Disable Frequent Metadata Updates
- Advanced Configuration: Customizing Metadata Refresh Intervals
- Verifying Metadata Update Settings
- Caveats and Considerations
- Conclusion
- References
1. Understanding Yum Repository Metadata#
Before diving into disabling updates, let’s clarify what repository metadata is and how Yum uses it.
Repository metadata is a set of XML-based files hosted on Yum repositories (e.g., repomd.xml, primary.xml.gz, filelists.xml.gz). These files act as a "catalog" for the repository, containing:
- A list of all packages in the repository.
- Package versions, sizes, and checksums.
- Dependencies required by each package.
- Repository signing keys (for security).
Yum downloads and caches this metadata locally (typically in /var/cache/yum/) to avoid re-downloading it on every command. By default, Yum checks if the cached metadata has "expired" (based on a timestamp) each time you run a command. If expired, it fetches fresh metadata from the repository.
2. Why Disable Frequent Metadata Updates?#
Frequent metadata updates are not always desirable. Here are common scenarios where disabling or reducing updates makes sense:
- Slow/Unreliable Networks: Metadata files can be large (tens to hundreds of MB for large repos like EPEL). Repeated downloads waste bandwidth and cause delays.
- Metered Connections: If you pay for data (e.g., cloud instances with limited bandwidth), frequent metadata checks increase costs.
- Stable Repositories: In environments where repositories are static (e.g., internal mirrors that rarely update), metadata checks are redundant.
- Automation/ Scripts: Tools like Ansible or custom scripts running
yumcommands may fail or slow down due to unexpected metadata downloads. - Avoid "Metadata Expired" Errors: If a repository is offline, Yum may throw errors like
Metadata file does not match checksumwhen it tries (and fails) to update metadata.
3. Methods to Disable Frequent Metadata Updates#
Yum provides multiple ways to control metadata updates, ranging from temporary command-line tweaks to permanent configuration changes.
3.1 Using Command-Line Options#
For one-off tasks, you can override Yum’s default metadata behavior using command-line flags. These options take precedence over configuration files.
3.1.1 Cache-Only Mode (-C or --cacheonly)#
The -C (or --cacheonly) flag tells Yum to use only cached metadata and packages, skipping all remote checks. It will not download new metadata or packages, even if the cached data is expired.
Example:
yum -C install httpd # Installs httpd using only cached metadata/packages
yum --cacheonly update # Checks for updates using cached metadataNote: If the cache is empty (e.g., first run), -C will fail with an error like Error: No cached data available.
3.1.2 Disable Metadata Expiration Temporarily#
Use --setopt=metadata_expire=never to force Yum to treat cached metadata as "never expired" for the current command. This avoids re-downloading metadata but still allows package downloads (unlike -C).
Example:
yum --setopt=metadata_expire=never install nginx3.2 Modifying Global Yum Configuration (yum.conf)#
For permanent changes affecting all Yum commands, edit the global configuration file /etc/yum.conf. This file controls Yum’s default behavior for all repositories.
Step 1: Open yum.conf in a Text Editor#
sudo vi /etc/yum.conf3.2.1 Disable Metadata Updates Globally#
Add or modify the metadata_expire directive in the [main] section of yum.conf. This sets how long (in seconds) Yum considers cached metadata valid.
To disable updates entirely, set metadata_expire=never:
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
metadata_expire=never # Disable metadata expiration (never update)3.2.2 Set a Custom Expiration Interval#
Instead of never, you can set a specific interval (e.g., 1 day, 1 week) to balance freshness and efficiency. Use suffixes like s (seconds), m (minutes), h (hours), or d (days) for readability.
Examples:
metadata_expire=3600 # 1 hour (3600 seconds)
metadata_expire=1d # 1 day
metadata_expire=7d # 1 week3.3 Per-Repository Configuration#
If you want to customize metadata updates for specific repositories (e.g., a stable internal repo vs. a frequently updated upstream repo), modify the repository’s .repo file in /etc/yum.repos.d/.
Most Linux distributions store repo files (e.g., epel.repo, rhel-baseos.repo) in /etc/yum.repos.d/. Each repo file contains sections like [epel] or [base] for individual repositories.
Step 1: Edit the Repository File#
For example, to modify the EPEL repository:
sudo vi /etc/yum.repos.d/epel.repoStep 2: Add metadata_expire to the Repo Section#
In the repo section (e.g., [epel]), add metadata_expire to control how often Yum updates metadata for that repo.
Example:
[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
baseurl=https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$releasever
metadata_expire=3d # Update EPEL metadata every 3 daysNote: Per-repo metadata_expire settings override the global yum.conf value for that specific repository.
4. Advanced Configuration: Customizing Metadata Refresh Intervals#
Yum’s metadata_expire directive supports flexible time formats beyond raw seconds. Here’s how to fine-tune intervals:
| Value | Meaning | Example Use Case |
|---|---|---|
600 | 600 seconds (10 minutes) | Fast-changing repos (e.g., testing) |
2h | 2 hours | Moderately updated repos |
1d | 1 day | Stable production repos |
30d | 30 days | Rarely updated internal repos |
never | No expiration | Offline/air-gapped environments |
Example: Mixing Global and Per-Repo Intervals#
Suppose you want:
- Global metadata to expire every 1 day.
- The EPEL repo to expire every 3 days.
- A custom internal repo (
[my-internal-repo]) to never expire.
Global yum.conf:
[main]
...
metadata_expire=1d # Global default: 1 dayPer-repo config (/etc/yum.repos.d/epel.repo):
[epel]
...
metadata_expire=3d # Override: 3 days for EPELPer-repo config (/etc/yum.repos.d/my-internal.repo):
[my-internal-repo]
name=My Internal Repo
baseurl=http://internal-server/repo/
enabled=1
gpgcheck=0
metadata_expire=never # Never update metadata for this repo5. Verifying Metadata Update Settings#
To confirm your metadata settings are working, use yum repolist -v (verbose repolist). This command displays detailed information about each repository, including metadata expiration times.
Example Output:
yum repolist -vLook for lines like:
Repo-id : epel
Repo-name : Extra Packages for Enterprise Linux 8 - x86_64
Repo-revision: 1694567890
Repo-updated : Wed Sep 13 12:34:50 2023
Repo-pkgs : 13,456
Repo-size : 25 G
Repo-baseurl : https://download.fedoraproject.org/pub/epel/8/x86_64/
Repo-expire : 3 days (last: Wed Sep 13 12:34:50 2023) # <-- Expiration interval
Filter : read-only:present
Repo-filename: /etc/yum.repos.d/epel.repo
Here, Repo-expire: 3 days confirms the EPEL repo’s metadata is set to expire every 3 days.
6. Caveats and Considerations#
While disabling metadata updates improves efficiency, it comes with trade-offs. Be mindful of these risks:
6.1 Outdated Package Information#
If metadata is never updated, Yum will not see new packages, version updates, or security patches added to repositories. This can leave systems vulnerable or prevent installation of newer software versions.
6.2 "Metadata Expired" Errors#
If you set metadata_expire=never but the repository does update, Yum may fail to detect new packages or dependencies, leading to errors like Package X not found.
6.3 Cache Corruption#
Cached metadata can become corrupted over time. If you encounter strange errors, refresh the cache manually:
yum clean metadata # Deletes cached metadata
yum makecache # Rebuilds metadata cache7. Conclusion#
Disabling or customizing Yum’s frequent metadata updates is a powerful way to optimize performance in bandwidth-constrained, stable, or offline environments. By using command-line flags (e.g., -C), modifying yum.conf, or tuning per-repo settings, you can balance efficiency with the need for up-to-date package information.
Best Practices:
- Avoid
metadata_expire=neverin production unless repositories are strictly static. - Use reasonable intervals (e.g., 1–7 days) for most use cases.
- Refresh metadata manually (
yum clean metadata && yum makecache) after repo updates.