CentOS中設(shè)置yum源的詳細(xì)步驟
在CentOS中設(shè)置yum源可以分為以下幾個步驟。我將以設(shè)置阿里云鏡像源為例進行說明:
1. 備份原有yum源
# 備份原有repo文件 sudo cp -r /etc/yum.repos.d /etc/yum.repos.d.backup # 刪除原有repo文件 sudo rm -rf /etc/yum.repos.d/*.repo
2. 下載新的yum源文件
根據(jù)你的CentOS版本選擇相應(yīng)的源:
CentOS 7
# 下載阿里云Base源 sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # 下載EPEL源 sudo yum install -y epel-release sudo curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
CentOS 8
# 下載阿里云Base源 sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo # 下載EPEL源 sudo dnf install -y epel-release sudo curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-8.repo
3. 生成緩存
# 清理緩存 sudo yum clean all # 生成新緩存 sudo yum makecache # 更新系統(tǒng) sudo yum update -y
4. 其他常用鏡像源
如果需要使用其他鏡像源,可以替換URL:
清華鏡像源
- CentOS 7:
https://mirrors.tuna.tsinghua.edu.cn/repo/centos-repo/7.repo - CentOS 8:
https://mirrors.tuna.tsinghua.edu.cn/repo/centos-repo/8.repo
網(wǎng)易鏡像源
- CentOS 7:
http://mirrors.163.com/.help/CentOS7-Base-163.repo - CentOS 8:
http://mirrors.163.com/.help/CentOS8-Base-163.repo
5. 手動配置yum源文件示例
如果需要手動創(chuàng)建,可以編輯 /etc/yum.repos.d/centos.repo:
[base] name=CentOS-$releasever - Base baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [updates] name=CentOS-$releasever - Updates baseurl=https://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [extras] name=CentOS-$releasever - Extras baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
6. 驗證yum源
# 查看已配置的yum源 yum repolist all # 測試安裝軟件包 yum search nginx
7. 常見問題解決
如果遇到GPG key錯誤:
# 導(dǎo)入GPG key sudo rpm --import https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
如果遇到緩存問題:
# 完全清理 sudo yum clean all sudo rm -rf /var/cache/yum sudo yum makecache
這樣就完成了CentOS yum源的設(shè)置。使用國內(nèi)鏡像源可以顯著提高軟件包的下載速度。
到此這篇關(guān)于CentOS中設(shè)置yum源的詳細(xì)步驟的文章就介紹到這了,更多相關(guān)CentOS中設(shè)置yum源內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Linux系統(tǒng)內(nèi)存不足導(dǎo)致服務(wù)崩潰的排查方法
Linux 系統(tǒng)內(nèi)存不足會導(dǎo)致服務(wù)崩潰、系統(tǒng)變慢甚至無法正常運行,以下是內(nèi)存不足問題的詳細(xì)排查方法,包括問題癥狀、原因分析及解決步驟,2025-08-08
ubuntu20.04 LTS系統(tǒng)默認(rèn)源sources.list文件的修改
這篇文章主要介紹了ubuntu20.04 LTS系統(tǒng)默認(rèn)源sources.list文件的修改,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08
Linux下環(huán)境變量配置方法小結(jié)(.bash_profile和.bashrc的區(qū)別)
這篇文章主要介紹了Linux下環(huán)境變量配置方法小結(jié)(.bash_profile和.bashrc的區(qū)別),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04
linux系統(tǒng)實現(xiàn)重啟網(wǎng)卡命令
本文介紹了三種在Linux系統(tǒng)中重啟網(wǎng)卡的方法,包括使用服務(wù)命令、ifconfig命令以及ifdown/ifup命令,這些方法可以幫助系統(tǒng)管理員在維護或故障排除時快速恢復(fù)網(wǎng)絡(luò)連接2025-10-10

