在 CentOS 系统中,你可以通过编辑 /etc/yum.repos.d/ 目录下的 .repo 文件来设置本地 Yum 源
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
vi 编辑器作为示例:sudo vi /etc/yum.repos.d/CentOS-Base.repo
[baseos] 部分,找到 baseurl 配置项,将其替换为你的本地存储库的 URL。例如,如果你的本地存储库位于 /var/www/html/centos,则将其更改为:baseurl=http://localhost/centos/$releasever/$basearch/os/
同时,确保 mirrorlist 配置项被注释掉或删除,以避免使用默认的远程镜像源:
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
如果你还想添加其他存储库(如 CentOS Plus 或 CentOS Extras),可以在文件末尾添加相应的 [extras] 或 [centosplus] 部分,并设置 baseurl 为你的本地存储库 URL。
保存并关闭文件。
清除缓存并更新系统:
sudo yum clean all
sudo yum makecache
sudo yum update
现在,你已经成功设置了 CentOS 的本地 Yum 源。你可以使用 yum 命令安装、更新和删除软件包,就像使用官方源一样。