在yum仓库中设置优先级,可以通过以下步骤实现:
方法一:使用priority参数
-
编辑仓库配置文件:
- 打开位于/etc/yum.repos.d/目录下的Yum仓库配置文件,通常这些文件以.repo为扩展名,例如CentOS-Base.repo。
-
设置优先级:
- 在每个仓库的配置块中,添加或修改priority参数。
- priority的值是一个整数,数值越大,优先级越低。
示例:
[base] name=CentOS-$releasever - Base baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7[updates] name=CentOS-$releasever - Updates baseurl=https://www.php.cn/link/b34fcbb8b9dae62f171ff71744191f0e gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 priority=10
[extras] name=CentOS-$releasever - Extras baseurl=https://www.php.cn/link/154fa0133bf213ebda06227166605423 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 priority=5
方法二:使用repoquery命令
如果你不想直接编辑配置文件,可以使用repoquery命令来临时设置优先级。
- 查看当前仓库列表:
repoquery --repos
- 设置特定仓库的优先级:
repoquery --setopt=priorities=10
其中
注意事项
- 优先级范围:通常优先级的范围是1到99,数值越大表示优先级越低。
- 冲突解决:如果多个仓库提供了相同的包,Yum会根据优先级来选择哪个仓库的包进行安装。
- 持久性:通过编辑配置文件设置的优先级是持久的,而使用repoquery命令设置的优先级只在当前会话中有效。
示例
假设你想将epel仓库的优先级设置为最低(99),可以这样做:
- 编辑配置文件:
[epel] name=Extra Packages for Enterprise Linux $releasever - $basearch baseurl=https://www.php.cn/link/fdba1a7e539c5c1cce7293fe6ae09ee6 enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 priority=99
- 或者使用repoquery命令:
repoquery --setopt=priorities=99 epel
通过以上方法,你可以灵活地设置Yum仓库的优先级,以满足不同的需求。











