由于Ubuntu默认的软件源的服务器在国外,所以使用默认的软件源会导致ubuntu安装更新软件很慢,因此我们需要修改ubuntu的软件源为国内的镜像服务器。
在 Ubuntu 24.04 之前,Ubuntu 的软件源配置文件使用传统的 One-Line-Style,路径为 /etc/apt/sources.list
;从 Ubuntu 24.04 开始,Ubuntu 的软件源配置文件变更为 DEB822 格式,路径为 /etc/apt/sources.list.d/ubuntu.sources
。
准备
更换国内镜像源时,先备份原文件
jagitch@f6edbab4586d:~$ sudo cp /etc/apt/sources.list.d/ubuntu.sources \
/etc/apt/sources.list.d/ubuntu.sources.bak
将Ubuntu24.04软件源更换为清华大学镜像源
将/etc/apt/sources.list.d/ubuntu.sources
修改为如下内容:
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
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
# Types: deb-src
# 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: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# Types: deb-src
# URIs: http://security.ubuntu.com/ubuntu/
# Suites: noble-security
# 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-proposed
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# # Types: deb-src
# # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# # Suites: noble-proposed
# # Components: main restricted universe multiverse
# # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
修改文件后执行更新
jagitch@f6edbab4586d:~$ sudo apt update
可能遇到的问题
-
No system certificates available. Try installing ca-certificates.
解决方法:
# 恢复文件 jagitch@f6edbab4586d:~$ sudo mv /etc/apt/sources.list.d/ubuntu.sources.bak \ /etc/apt/sources.list.d/ubuntu.sources jagitch@f6edbab4586d:~$ sudo apt clean jagitch@f6edbab4586d:~$ sudo apt update jagitch@f6edbab4586d:~$ sudo apt install -y ca-certificates jagitch@f6edbab4586d:~$ sudo update-ca-certificates jagitch@f6edbab4586d:~$ sudo apt-get update
然后重新更换软件源即可
推荐阅读
1. 使用树梅派搭建Golang、Python、NodeJs的开发服务器
2. 如何将github开源项目发布
3. 教你如何1秒安装一个Linux系统(ubuntu,debian,centos) 比虚拟机安装系统省时省心省力