复制成功
请遵守本站许可
REPORT
Chapter_Post // Field_Report

Post_Ref: RL-UBUNTU24

2026.04.08

Ubuntu24.04换源教程

Echo HaoRan
Echo HaoRan
ANALYSIS

常用国内镜像源#

阿里云镜像源#

PRTCL // PLAINTEXT
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse

清华大学镜像源#

PRTCL // PLAINTEXT
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-security main restricted universe multiverse

中科大镜像源#

PRTCL // PLAINTEXT
deb https://mirrors.ustc.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ noble-security main restricted universe multiverse

网易镜像源#

PRTCL // PLAINTEXT
deb https://mirrors.163.com/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.163.com/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.163.com/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirrors.163.com/ubuntu/ noble-security main restricted universe multiverse

换源步骤#

第一步:备份原有源文件#

PRTCL // BASH
Terminal window
sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak

第二步:查看当前源配置#

Ubuntu 24.04 使用新的 DEB822 格式:

PRTCL // BASH
Terminal window
cat /etc/apt/sources.list.d/ubuntu.sources

第三步:编辑源文件#

PRTCL // BASH
Terminal window
sudo nano /etc/apt/sources.list.d/ubuntu.sources

第四步:替换源内容#

方法 1:使用 DEB822 格式 ( 推荐 )#

将文件内容替换为以下内容 ( 以阿里云为例 ):

PRTCL // PLAINTEXT
Types: deb
URIs: https://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: https://mirrors.aliyun.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

清华源 DEB822 格式:

PRTCL // PLAINTEXT
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

中科大源 DEB822 格式:

PRTCL // PLAINTEXT
Types: deb
URIs: https://mirrors.ustc.edu.cn/ubuntu/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: https://mirrors.ustc.edu.cn/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

方法 2:使用传统格式#

如果需要使用传统格式,可以编辑/etc/apt/sources.list:

PRTCL // BASH
Terminal window
sudo nano /etc/apt/sources.list

添加以下内容 ( 以阿里云为例 ):

PRTCL // PLAINTEXT
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse

参数说明:

  • deb: 二进制软件包
  • deb-src: 源代码包 ( 可选 )
  • noble: Ubuntu 24.04 的代号
  • main: 官方支持的自由软件
  • restricted: 官方支持的非完全自由软件
  • universe: 社区维护的自由软件
  • multiverse: 非自由软件

第五步:保存文件#

  • nano 编辑器: 按Ctrl + O保存,Ctrl + X退出
  • vim 编辑器: 按ESC,输入:wq保存退出

第六步:更新软件包列表#

PRTCL // BASH
Terminal window
sudo apt update

第七步:升级已安装的软件包 ( 可选 )#

PRTCL // BASH
Terminal window
sudo apt upgrade -y

一键换源脚本#

阿里云源#

PRTCL // BASH
Terminal window
sudo sed -i 's@//.*archive.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list.d/ubuntu.sources
sudo apt update

清华源#

PRTCL // BASH
Terminal window
sudo sed -i 's@//.*archive.ubuntu.com@//mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list.d/ubuntu.sources
sudo apt update

中科大源#

PRTCL // BASH
Terminal window
sudo sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list.d/ubuntu.sources
sudo apt update

验证换源成功#

查看当前源配置#

PRTCL // BASH
Terminal window
cat /etc/apt/sources.list.d/ubuntu.sources

测试下载速度#

PRTCL // BASH
Terminal window
sudo apt update

观察下载速度,应该明显提升。

安装测试软件#

PRTCL // BASH
Terminal window
sudo apt install neofetch -y

如果安装速度很快,说明换源成功。

恢复默认源#

如果换源后出现问题,可以恢复备份:

PRTCL // BASH
Terminal window
sudo cp /etc/apt/sources.list.d/ubuntu.sources.bak /etc/apt/sources.list.d/ubuntu.sources
sudo apt update

或手动恢复为官方源:

PRTCL // BASH
Terminal window
sudo nano /etc/apt/sources.list.d/ubuntu.sources

替换为官方源:

PRTCL // PLAINTEXT
Types: deb
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

常见问题#

更新时出现 GPG 错误#

PRTCL // BASH
Terminal window
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <KEY_ID>

或重新获取密钥:

PRTCL // BASH
Terminal window
sudo apt update --allow-insecure-repositories

无法连接到镜像源#

检查网络连接:

PRTCL // BASH
Terminal window
ping mirrors.aliyun.com

尝试更换其他镜像源。

更新速度仍然很慢#

  • 尝试更换其他镜像源
  • 检查本地网络状况
  • 使用apt-fast加速下载

安装 apt-fast:

PRTCL // BASH
Terminal window
sudo add-apt-repository ppa:apt-fast/stable
sudo apt update
sudo apt install apt-fast -y

sources.list.d 目录下没有 ubuntu.sources 文件#

Ubuntu 24.04 之前的版本使用/etc/apt/sources.list,直接编辑该文件:

PRTCL // BASH
Terminal window
sudo nano /etc/apt/sources.list

提示”仓库不支持架构”#

确认系统架构:

PRTCL // BASH
Terminal window
dpkg --print-architecture

如果是 ARM 架构,需要使用对应的 ARM 镜像源。

其他软件源配置#

PPA 源换源#

编辑 PPA 源文件:

PRTCL // BASH
Terminal window
sudo nano /etc/apt/sources.list.d/<ppa-name>.list

Docker 源换源#

PRTCL // BASH
Terminal window
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://docker.mirrors.ustc.edu.cn",
"https://hub-mirror.c.163.com",
"https://mirror.ccs.tencentyun.com"
]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

Python pip 换源#

临时使用:

PRTCL // BASH
Terminal window
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple <package>

永久配置:

PRTCL // BASH
Terminal window
mkdir -p ~/.pip
cat > ~/.pip/pip.conf <<EOF
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn
EOF

Node.js npm 换源#

PRTCL // BASH
Terminal window
npm config set registry https://registry.npmmirror.com

验证:

PRTCL // BASH
Terminal window
npm config get registry

推荐镜像源选择#

教育网用户#

推荐使用教育网镜像:

  • 清华大学镜像源
  • 中科大镜像源
  • 上海交大镜像源

电信用户#

推荐使用:

  • 阿里云镜像源
  • 网易镜像源

联通 / 移动用户#

推荐使用:

  • 阿里云镜像源
  • 腾讯云镜像源

海外用户#

使用官方源或就近的区域镜像。

镜像源速度测试#

使用 netselect-apt 自动选择最快源#

安装工具:

PRTCL // BASH
Terminal window
sudo apt install netselect-apt -y

测试并生成 sources.list:

PRTCL // BASH
Terminal window
sudo netselect-apt noble

手动测试下载速度#

PRTCL // BASH
Terminal window
wget -O /dev/null http://mirrors.aliyun.com/ubuntu/ls-lR.gz
wget -O /dev/null http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ls-lR.gz
wget -O /dev/null http://mirrors.ustc.edu.cn/ubuntu/ls-lR.gz

比较下载速度,选择最快的源。

参考资料#

R P
Rhine Lab Pioneer Division
Auth_Verified: 2026.04.08
// END OF POST

订阅

通过 RSS 订阅本站,新文章发布时第一时间收到通知。

Follow
Classified
Chapter_06
Protocol_Ref: CC-BY-NC-SA-4.0

Ubuntu24.04换源教程

Author: CHONGXIReleased: 2026.04.08

Licensed under CC BY-NC-SA 4.0

评论

© 2025-2026 EchoSpace
Powered by Astro & echohaoran Non-Collaborative_Entity // Protocol_V.4.21