麻花痒 发表于 2025-1-3 04:09:13

Linux国内镜像源具体修改教程

Linux体系下,CentOS和Ubuntu的镜像源修改教程因版本差别而有所差异。以下是针对CentOS 7至9以及Ubuntu 16.04至22.04的国表里镜像源修改教程:
CentOS

CentOS 7


[*] 备份原有的YUM源文件:
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
[*] 选择并下载国内镜像源:

[*] 阿里云源:
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[*] 网易源:
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

[*] 清理原有缓存并生成新缓存:
sudo yum clean all
sudo yum makecache
[*] 更新体系:
sudo yum update -y
CentOS 8


[*] 备份原有的YUM源文件:
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[*] 选择并下载国内镜像源:

[*] 阿里云源:
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

[*] 清理原有缓存并生成新缓存:
sudo yum clean all
sudo yum makecache
[*] 更新体系:
sudo yum update -y
CentOS 9


[*] 备份原有的YUM配置文件:
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base-backup.repo
[*] 选择并添加国内镜像源:

[*] 阿里云源:
打开编辑器(如vi或nano):
sudo vi /etc/yum.repos.d/CentOS-Base.repo 在文件末尾追加阿里云的CentOS镜像源配置:

name=阿里云CentOS mirror
baseurl=https://mirrors.aliyun.com/repo/CentOS-$releasever/
gpgcheck=0
enabled=1 留意:$releasever必要更换为你的CentOS 9版本(例如"stream")。

[*] 清理原有缓存并生成新缓存:
sudo yum clean all
sudo yum makecache fast
[*] 更新体系:
sudo yum update -y
Ubuntu

Ubuntu 16.04


[*] 备份源文件:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
[*] 修改源文件:
利用文本编辑器(如gedit、vi、nano等)打开/etc/apt/sources.list文件,将原有的全部源表明掉,并添加国内源。例如,添加阿里云源:
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
[*] 更新源文件:
sudo apt update
Ubuntu 18.04


[*] 备份源文件:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
[*] 修改源文件:
利用文本编辑器打开/etc/apt/sources.list文件,将原有的全部源表明掉,并添加国内源。例如,添加阿里云源:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
[*] 更新源文件:
sudo apt update
Ubuntu 20.04 和 22.04

对于Ubuntu 20.04和22.04,修改源文件的步骤与18.04类似。只需将源文件中的版本号(如bionic)更换为对应版本的代号(如focal对应20.04,jammy对应22.04),并添加相应的国内源地址即可。
以下是Ubuntu 20.04和22.04国内镜像源修改的具体教程:
Ubuntu 20.04 国内镜像源修改教程


[*] 备份原有的镜像源文件
打开终端(Ctrl+Alt+T),输入以下命令备份原有的Ubuntu 20.04镜像源文件:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
[*] 编辑镜像源文件
利用文本编辑器(如nano或vim)打开/etc/apt/sources.list文件,并将原有的镜像源地址更换为国内镜像源地址。例如,利用nano编辑器:
sudo nano /etc/apt/sources.list 将文件中的内容更换为以下格式(以清华大学镜像源为例):
# 默认注释掉的源,如果需要启用,请取消注释并将下面的清华大学源地址替换为官方源地址
# deb http://archive.ubuntu.com/ubuntu/ focal main restricted
# deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
# deb http://archive.ubuntu.com/ubuntu/ focal universe
# deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
# deb http://archive.ubuntu.com/ubuntu/ focal multiverse
# deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
# deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
# deb http://security.ubuntu.com/ubuntu/ focal-security main restricted
# deb http://security.ubuntu.com/ubuntu/ focal-security universe
# deb http://security.ubuntu.com/ubuntu/ focal-security multiverse

# 替换为清华大学镜像源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse 生存并退出编辑器。
[*] 更新软件包索引
输入以下命令更新软件包索引,以确保体系能够辨认新的镜像源:
sudo apt update
[*] 验证新配置的镜像源
可以通过实验安装一个软件包来验证新配置的镜像源是否见效。例如,安装curl:
sudo apt install curl 假如安装过程顺利且速度较快,说明新配置的镜像源已经见效。
Ubuntu 22.04 国内镜像源修改教程


[*] 安装software-properties-common
打开终端,输入以下命令安装software-properties-common:
sudo apt update && sudo apt install software-properties-common
[*] 添加国内镜像源
以添加清华大学源为例,输入以下命令:
sudo add-apt-repository "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse"
sudo add-apt-repository "deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse" 假如必要添加阿里云源,可以利用以下命令(留意更换为正确的仓库地址):
sudo add-apt-repository ppa:chenyunkun/aliyun-ubuntu-repo
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E56151AF
# 然后编辑 /etc/apt/sources.list 文件,将原有的源替换为阿里云源 或者直接编辑/etc/apt/sources.list文件,将原有的源更换为阿里云源,例如:
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
[*] 更新软件包索引
输入以下命令更新软件包索引:
sudo apt update
[*] 验证新配置的镜像源
同样可以通过实验安装一个软件包来验证新配置的镜像源是否见效。
通过以上步骤,您可以成功在Ubuntu 20.04和22.04中配置国内镜像源,从而提拔软件包下载速度。
留意事项


[*]在修改镜像源之前,请确保网络连接正常,并能够访问所选的国内镜像源。
[*]修改镜像源大概会影响软件包的可用性和安全性,因此请确保选择可靠的国内源。
[*]定期检查和更新源列表文件,以确保体系能够获取到最新的软件包和更新。
通过以上步骤,您可以成功修改CentOS 7至9以及Ubuntu 16.04至22.04的国表里镜像源。
原文链接:Linux国内镜像源具体修改教程 - Java程序员_编程开发学习条记_网站安全运维教程_渗透技术教程

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Linux国内镜像源具体修改教程