1.使用 CentOS Vault 倉庫
CentOS 7 已進入維護階段,大部分映象源已經不再提供更新。但是,CentOS Vault 倉庫中包含了所有歷史版本的包。
1.1 編輯 /etc/yum.repos.d/CentOS-Base.repo 檔案:
sudo vi /etc/yum.repos.d/CentOS-Base.repo
1.2 將內容替換為:
點選檢視程式碼
[base]
name=CentOS-$releasever - Base
baseurl=http://vault.centos.org/7.9.2009/os/$basearch/
gpgcheck=0
gpgkey=http://vault.centos.org/7.9.2009/os/x86_64/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates
baseurl=http://vault.centos.org/7.9.2009/updates/$basearch/
gpgcheck=0
gpgkey=http://vault.centos.org/7.9.2009/updates/x86_64/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras
baseurl=http://vault.centos.org/7.9.2009/extras/$basearch/
gpgcheck=0
gpgkey=http://vault.centos.org/7.9.2009/extras/x86_64/RPM-GPG-KEY-CentOS-7
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://vault.centos.org/7.9.2009/centosplus/$basearch/
gpgcheck=0
enabled=0
gpgkey=http://vault.centos.org/7.9.2009/centosplus/x86_64/RPM-GPG-KEY-CentOS-7
或者替換為:
點選檢視程式碼
[base]
name=CentOS-$releasever - Base - aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates - aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras - aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[centosplus]
name=CentOS-$releasever - Plus - aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
1.3 儲存檔案,然後再次清理快取並重新生成快取:
sudo yum clean all
sudo yum makecache
1.4 最後,測試更新:
注意:部分包源也是沒有的,那就需要自己手動下載和匯入了
yum install vim -y
2. 遷移到其他 CentOS 相容的發行版
如果你長期需要更新和支援,可以考慮遷移到 CentOS 的後繼專案,如 AlmaLinux 或 Rocky Linux。這些專案提供了與 CentOS 完全相容的替代方案,並且有更長的支援週期。
如果只是做一個學習瞭解,可以不用管那麼多了。