AI 摘要(由 ChatGPT 总结生成):
本文介绍了在主流Linux系统中替换国内源的方法。对于Debian系统,通过编辑`/etc/apt/sources.list`文件,可以选择清华源或中科大源。对于Ubuntu系统,同样编辑`/etc/apt/sources.list`文件,可选择清华源、阿里源或中科大源。CentOS系统可以通过替换`/etc/yum.repos.d/CentOS-Base.repo`文件中的源为阿里源或清华源。最后,对于Kali系统,编辑`/etc/apt/sources.list`文件,可选择中科大源、阿里源或清华源。每次编辑后需执行相应的命令使更改生效。

在使用Linux系统的小伙伴在安装软件的时候肯定有被网速困扰到,明明自己的网络状况很好,却偏偏在安装软件时网速如此的慢,其主要的原因是源的问题,Linux系统默认的都是国外的源,在国内访问速度会很慢很慢,那么本文就分享一波博主自用的源设置。

Debian源替换

Debian 的源配置文件是 /etc/apt/sources.list
1、首先给源文件备份,命令如下:

cp /etc/apt/sources.list /etc/apt/sources.list.bak

2、为防止https源无法拉取情况,请在编辑源之前安装一下https证书

apt install apt-transport-https ca-certificates

3、使用vi编辑器编辑sources.list文件(也可使用nano编辑器)

vi /etc/apt/sources.list

i键进入编辑模式,将默认源给注释掉然后添加下方的源镜像代码:
清华源:

# 清华源
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free

中科大源:

# 中科大源
deb https://mirrors.ustc.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ buster-backports main contrib non-free
deb https://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ buster main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ buster-updates main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ buster-backports main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free

添加的源使用其一即可,添加完毕后按下ESC键,输入:wq保存并退出,接下来执行一遍apt-get update更新一下索引使其生效。

Ubuntu源替换

Ubuntu 的源配置文件是 /etc/apt/sources.list
1、首先给源文件备份,命令如下:

cp /etc/apt/sources.list /etc/apt/sources.list.bak

2、使用vi编辑器编辑sources.list文件(也可使用nano编辑器)

vi /etc/apt/sources.list

i键进入编辑模式,将默认源给注释掉然后添加下方的源镜像代码:
清华源:

# 清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates 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-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

# 预发布软件源
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

阿里源:

# 阿里源
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

# 预发布软件源
# deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

中科大源:

# 中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse

# 预发布软件源
# deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

添加的源使用其一即可,若要使用预发布软件源,可取消前面的注释,添加完毕后按下ESC键,输入:wq保存并退出,接下来执行一遍apt-get update更新一下索引使其生效。

CentOS源替换

CentOS 的源配置文件是 /etc/yum.repos.d/CentOS-Base.repo

替换为阿里源

1、先安装wget,若已安装请忽略,否则务必执行

yum install -y wget

2、给源文件备份,命令如下:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

3、下载阿里源的yum源配置文件到/etc/yum.repos.d/目录
CentOS 7:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

CentOS 6:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

4、之后运行yum makecache生成缓存

yum makecache

替换为清华源

此为CentOS 7的源替换,若不是该版本系统,请勿操作
1、给源文件备份,命令如下:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

2、新建CentOS-Base.repo文件

touch /etc/yum.repos.d/CentOS-Base.repo

3、使用vim编辑器编辑CentOS-Base.repo文件,按i键进入编辑模式,添加下方的源镜像代码:

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
 
[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

添加完毕后按下ESC键,输入:wq保存并退出
4、之后运行yum makecache生成缓存

yum makecache

Kali源替换

Kali 的源配置文件是 /etc/apt/sources.list
1、首先给源文件备份,命令如下:

cp /etc/apt/sources.list /etc/apt/sources.list.bak

2、使用vim编辑器编辑sources.list文件

vim /etc/apt/sources.list

i键进入编辑模式,将默认源给注释掉然后添加下方的源镜像代码:
中科大源:

# 中科大源
deb http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib
deb-src http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib

阿里源:

# 阿里源
deb http://mirrors.aliyun.com/kali kali-rolling main non-free contrib
deb-src http://mirrors.aliyun.com/kali kali-rolling main non-free contrib

清华源:

# 清华源
deb http://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling main contrib non-free

添加的源使用其一即可,添加完毕后按下ESC键,输入:wq保存并退出,接下来执行一遍apt-get update && apt-get upgrade && apt-get clean使其生效。

End

本文标题:主流Linux系统替换国内源

本文链接:https://www.isisy.com/835.html

除非另有说明,本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

声明:转载请注明文章来源。

如果觉得我的文章对你有用,请随意赞赏