CentOS中設(shè)置yum源的詳細步驟
在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源的詳細步驟的文章就介紹到這了,更多相關(guān)CentOS中設(shè)置yum源內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Linux強制釋放占用端口以及Linux防火墻端口開放方法詳解
在linux系統(tǒng)中安裝一些軟件時有時遇到端口被占用的情況,本文為大家介紹了遇到這種情況我們應(yīng)該怎么處理2018-10-10
Linux+php+apache+oracle環(huán)境搭建之CentOS下源碼編譯安裝PHP
環(huán)境搭建過程中,編譯安裝PHP最艱辛。需要安裝的依賴組件太多?,F(xiàn)在整理記錄一下。也希望對讀者能有所幫助2014-08-08
Ubuntu 18.04 安裝MySQL時未提示輸入密碼的問題及解決方法
這篇文章主要介紹了Ubuntu 18.04 安裝MySQL時未提示輸入密碼的問題及解決方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-10-10

