Operations guide

How to recover yum on old CentOS 7 hosts by switching repository mirrors

A practical guide for using switch-centos7-repo.sh when CentOS 7 default repositories are no longer usable and you need package installs to work again.

6 min read · 2026-03-26

When this script is useful

switch-centos7-repo.sh is meant for old CentOS 7 hosts where yum stops working because the default repository URLs have expired, moved, or become unreachable from the current region.

It is especially useful on inherited machines, archived internal systems, and maintenance hosts that still need package installs or dependency recovery before a larger change window.

What the script changes

The core job is to replace stale yum repository definitions with a working mirror source. That usually means rewriting repo files, refreshing yum metadata, and making package installation available again.

Because repository changes affect every later package install, this is the kind of script that should be reviewed once, documented clearly, and then reused consistently across similar legacy hosts.

  • Run the script with root privileges
  • Review the selected mirror and repo file changes
  • Run yum makecache or a small install test
  • Document the chosen source for future maintenance

Recommended operating pattern

A good pattern is to start with the one-liner from helper.sh, confirm the rewritten repository files, then validate yum with a safe command such as yum makecache or a basic package query.

If the host is important, back up the previous repo files first and record which mirror source was finally chosen. CentOS 7 is end-of-life, so repository recovery should be treated as a maintenance bridge, not the final state.

Related topics

CentOS 7 maintenance and recovery

Keep legacy CentOS 7 hosts installable and maintainable when yum repositories fail, mirrors expire, or Docker data needs to be moved off a crowded disk.

Open topic

Problem pages

How to fix CentOS 7 yum 404 errors

Restore package installation on old CentOS 7 hosts when the default repositories no longer work.

Open page

When should I switch CentOS 7 repositories

Switch repository definitions when old CentOS 7 mirrors fail, time out, or no longer return valid metadata.

Open page