跳到主要内容

切换国内源

手动切换方法

cat>/etc/apt/sources.list<<EOF
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src 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-backports main restricted universe multiverse
EOF
apt-get update
apt-get upgrade

上述更新源命令,报错,错误描述的是公钥不可用,无法验签:

The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 871920D1991BC93C

再次更新源

apt-get update
apt-get upgrade
cat>/etc/apt/sources.list<<EOF
deb http://mirrors.tencent.com/debian/ bullseye main non-free contrib
deb-src http://mirrors.tencent.com/debian/ bullseye main non-free contrib
deb http://mirrors.tencent.com/debian-security/ bullseye-security main
deb-src http://mirrors.tencent.com/debian-security/ bullseye-security main
deb http://mirrors.tencent.com/debian/ bullseye-updates main non-free contrib
deb-src http://mirrors.tencent.com/debian/ bullseye-updates main non-free contrib
deb http://mirrors.tencent.com/debian/ bullseye-backports main non-free contrib
deb-src http://mirrors.tencent.com/debian/ bullseye-backports main non-free contrib
EOF

使用开源工具一键切换

目前已有优秀的开源项目 linuxmirrors 实现了一键切换国内源的功能,支持Ubuntu、Debian、CentOS等主流Linux发行版,推荐使用该工具:

安装和使用方法

# 一键安装并运行
sudo bash <(curl -sSL https://linuxmirrors.cn/main.sh)

或者先下载后执行:

wget https://linuxmirrors.cn/main.sh
sudo bash ./main.sh

备用地址

sudo bash <(curl -sSL https://wengtx.cn/scripts/linuxmirrors/main.sh)

工具特性

  • 支持多种Linux发行版(Ubuntu、Debian、CentOS、Fedora等)
  • 自动识别系统类型和版本
  • 提供多个国内镜像源选择(阿里云、腾讯云、华为云、清华、中科大等)
  • 交互式菜单操作,简单易用
  • 自动备份原有配置文件
  • 支持IPv4/IPv6双栈环境
  • 支持HTTP/HTTPS协议切换
  • 支持系统架构识别(x86/arm等)

支持的镜像源

镜像源特点
阿里云覆盖全面,同步及时
腾讯云云服务商,访问速度快
华为云云服务商,稳定性好
清华大学教育网镜像,内容全面
中科大教育网镜像,同步及时
网易云商业镜像,速度稳定
搜狐商业镜像,历史悠久
浙大教育网镜像
南京大学教育网镜像
重庆大学教育网镜像
兰州大学教育网镜像
上海交通大学教育网镜像