Ubuntu 24.04 更换源教程

Ubuntu 24.04 版本更换源的方式有所变化,不再使用 sources.list 文件,而是改为使用 /etc/apt/sources.list.d/ubuntu.sources 配置文件。以下是更换为国内源的方式。

一、源文件位置

Ubuntu 24.04 采用新的源地址配置文件。升级到 24.04 之后,系统会使用以下文件来配置源:/etc/apt/sources.list.d/ubuntu.sources

二、开始更换源

1. 备份源配置文件

在进行任何更改之前,建议先备份当前的源配置文件:

1
sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak

2. 使用命令直接更换源

可以使用 curl 命令来直接更换源,以下命令将会下载源文件并替换掉原来的配置文件:

1
curl www.meiko.ink/sh/ubuntu.source > /etc/apt/sources.list.d/ubuntu.sources

3. 手动编辑源配置文件

手动编辑源配置文件,可以使用以下命令:

1
sudo vim /etc/apt/sources.list.d/ubuntu.sources

4. 添加中科大源

你可以手动将中科大的源添加到 ubuntu.sources 文件中。源配置如下:

1
2
3
4
5
Types: deb
URIs: http://mirrors.ustc.edu.cn/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

5. 更新缓存

1
sudo apt-get update

三、其他常见镜像源

以下几个常见的镜像源:

1
2
3
4
5
Types: deb
URIs: http://mirrors.tuna.tsinghua.edu.cn/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

清华源

1
2
3
4
5
Types: deb
URIs: http://mirrors.tuna.tsinghua.edu.cn/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

阿里云源

1
2
3
4
5
Types: deb
URIs: http://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

网易源

1
2
3
4
5
Types: deb
URIs: http://mirrors.163.com/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

成功更换了 Ubuntu 24.04 的源。如果遇到任何问题,可以随时恢复到备份的配置文件。