先备份原始源,再替换为阿里云源即可。
ubuntu 26.04(resolute raccoon)默认已经使用 .sources 格式,而不是老的 sources.list。
1. 备份原配置
sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak
2. 编辑镜像源
sudo vim /etc/apt/sources.list.d/ubuntu.sources
将内容替换为:
types: deb uris: https://mirrors.aliyun.com/ubuntu/ suites: resolute resolute-updates resolute-backports components: main restricted universe multiverse signed-by: /usr/share/keyrings/ubuntu-archive-keyring.gpg types: deb uris: https://mirrors.aliyun.com/ubuntu/ suites: resolute-security components: main restricted universe multiverse signed-by: /usr/share/keyrings/ubuntu-archive-keyring.gpg
3. 更新缓存
sudo apt update
4. 验证是否生效
apt policy
或者:
grep -e "mirrors.aliyun.com" /etc/apt/sources.list.d/ubuntu.sources
一键脚本(推荐)
直接执行:
sudo bash -c 'cat > /etc/apt/sources.list.d/ubuntu.sources <<eof types: deb uris: https://mirrors.aliyun.com/ubuntu/ suites: resolute resolute-updates resolute-backports components: main restricted universe multiverse signed-by: /usr/share/keyrings/ubuntu-archive-keyring.gpg types: deb uris: https://mirrors.aliyun.com/ubuntu/ suites: resolute-security components: main restricted universe multiverse signed-by: /usr/share/keyrings/ubuntu-archive-keyring.gpg eof' sudo apt update
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论