在 CentOS / RHEL / Rocky / Alma 等使用 yum / dnf 的系统中,添加仓库(repository)常见有以下几种方式。
.repo 文件手动添加(最常用 ✅)cd /etc/yum.repos.d/
.repo 文件例如添加一个自定义仓库:
vim myrepo.repo
示例:
[myrepo]
name=My Custom Repository
baseurl=http://example.com/repo/
enabled=1
gpgcheck=0
常用参数说明:
| 参数 | 说明 |
|---|---|
[myrepo] |
仓库 ID |
name |
仓库名称 |
baseurl |
仓库地址(http/https/ftp/file) |
enabled=1 |
启用仓库 |
gpgcheck=0 |
是否校验 GPG(0 关闭,1 开启) |
gpgkey |
GPG 公钥地址(如果开启 gpgcheck) |
✅ 如果是本地目录:
baseurl=file:///mnt/localrepo
yum-config-manager 添加(推荐)yum install -y yum-utils
yum-config-manager --add-repo=http://example.com/repo.repo
或:
yum-config-manager --add-repo http://example.com/repo/
yum install -y epel-release
或者手动:
yum-config-manager --add-repo=https://mirrors.aliyun.com/epel/epel-release-latest-$(rpm -E %rhel).noarch.rpm
yum repolist
或:
yum repolist all
yum --disablerepo=myrepo install xxx
yum --enablerepo=myrepo install xxx
yum clean all
yum makecache
ping example.com
curl http://example.com/repo/
gpgcheck=0(测试用)rpm --import /path/to/RPM-GPG-KEY
如果你愿意,可以告诉我:
我可以给你一条完全可直接执行的命令。