Ubuntu 24.04 更换源教程
Ubuntu 24.04 不再使用传统的 /etc/apt/sources.list
文件,而是采用 /etc/apt/sources.list.d/ubuntu.sources
配置文件来管理软件源。以下是更换为国内源的详细步骤。
1. 源文件位置
在 Ubuntu 24.04 中,软件源配置文件位于:
/etc/apt/sources.list.d/ubuntu.sources
2. 更换源步骤
2.1 备份源配置文件
在更改源之前,建议备份当前的配置文件以便恢复:
sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak
2.2 使用命令直接更换源
可以通过 curl
命令直接下载并替换源配置文件:
curl www.meiko.ink/sh/ubuntu.source > /etc/apt/sources.list.d/ubuntu.sources
注意:使用
tee
确保正确写入需要管理员权限的文件。执行前请确认www.meiko.ink
的可信度。
2.3 手动编辑源配置文件
若需手动编辑源文件,可使用以下命令打开配置文件:
sudo vim /etc/apt/sources.list.d/ubuntu.sources
2.4 添加中科大源
将以下中科大源配置写入 ubuntu.sources
文件:
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
2.5 更新缓存
更换源后,运行以下命令更新软件包缓存:
sudo apt-get update
3. 其他常见镜像源
以下是其他常用的国内镜像源配置,可根据需要选择替换:
3.1 清华源
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
3.2 阿里云源
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
3.3 网易源
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
4. 完成
成功更换 Ubuntu 24.04 的软件源!若遇到问题,可通过以下命令恢复备份:
sudo cp /etc/apt/sources.list.d/ubuntu.sources.bak /etc/apt/sources.list.d/ubuntu.sources
sudo apt-get update