Problem Description
On a freshly installed CentOS 7 64-bit system, when using the yum command to install software (e.g., docker-compose) or perform system updates, you may encounter the following issues:
- It reports
No packages marked for update, but updates are actually available. - Software installation fails, indicating no valid package found or repository metadata is expired.
This is typically caused by the system's default yum repository configuration being invalid, experiencing connection timeouts, or no longer being maintained.
Solution: Configure Alibaba Cloud Mirror Repository
Alibaba Cloud provides a stable and fast CentOS mirror repository, making it an effective replacement for the default source. Below are the detailed configuration steps.
Step 1: Download the Alibaba Cloud CentOS 7 Repo File
First, download the official CentOS 7 repository configuration file from Alibaba Cloud.
cd /tmp
curl -O http://mirrors.aliyun.com/repo/Centos-7.repo
Note: Using /tmp as a temporary workspace is standard practice. The original step mkdir alirepo is not necessary.
Step 2: Backup and Replace the System Default Repository Files
Before replacing, always back up the original system repository configuration files.
# Navigate to the yum repository configuration directory
cd /etc/yum.repos.d/
# Backup the original CentOS-Base repository file
sudo mv CentOS-Base.repo CentOS-Base.repo.backup
# Copy the downloaded Alibaba Cloud repo file to this directory and rename it to the standard name
sudo cp /tmp/Centos-7.repo /etc/yum.repos.d/CentOS-Base.repo
Important Correction: The original content's direct mv Centos-7.repo CentOS-Base.repo command assumed you were already in the directory and didn't use sudo. The standardized commands above are clearer and account for permissions.
Step 3: Clear Cache and Rebuild Metadata
After replacing the repository file, you need to clear the old yum cache and generate cache data for the new source.
# Clear all caches
sudo yum clean all
# Optional: Remove the cache directory (more thorough)
sudo rm -rf /var/cache/yum
# Build cache for the new repository
sudo yum makecache
# Perform a system update to apply the new source
sudo yum update -y
Verification and Next Steps
After completing the steps above, try installing software again, for example:
sudo yum install docker-compose -y
You should now be able to download and install packages normally from the Alibaba Cloud mirror.
Common Issues and Notes
- Regarding the EPEL Repository: Many third-party software packages (like newer versions of
docker-compose) depend on the EPEL repository. If you still need it, you can similarly replace it with Alibaba Cloud's EPEL source:sudo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo - Network Issues: Ensure your server has network connectivity and can access
mirrors.aliyun.com. - System Version: This guide is only for CentOS 7. Configuration for CentOS 8/Stream or Rocky/AlmaLinux is different; please refer to the corresponding mirror site documentation.
Important: Since CentOS 7 reached its End of Life (EOL) in June 2024, official repositories have stopped receiving updates. It is strongly recommended to consider migrating to a maintained alternative distribution like Rocky Linux or AlmaLinux. If you must continue using CentOS 7, configuring a reliable mirror source (like Alibaba Cloud or Tencent Cloud) is essential for ensuring software installation and updates.