Ubuntu更换国内apt-get源

更换方法:

cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
apt-get update 

腾讯云:mirrors.tencentyun.com

其中,
清华源域名:mirrors.tuna.tsinghua.edu.cn更多帮助
中科大源域名:mirrors.ustc.edu.cn更多帮助)  帮助:http://mirrors.ustc.edu.cn/help/ubuntu.html

 

这是一种正则得方法\/就是转义为/

sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

↑ 此条已验证可以
sudo apt-get update

 

真正完全的国内源举例:

# 默认注释了源码仓库,如有需要可自行取消注释
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

 

阿里云源

deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main
 
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main
 
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
 
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe
 
修改完文件要再更新源
 
更新软件包列表
sudo apt-get update
 
休复损坏的软件包,尝试卸载出错的包,重新安装正确版本的。
sudo apt-get -f install
 
升级系统中的所有软件包
sudo apt-get -y upgrade
 
问题1:
如Ubuntu16.04的开发代号是Xenial, 代号buster要做相应修改.也有可能是focal 
如要用于其他版本,把 focal 换成其他版本代号即可: 20.04:focal;18.04:bionic;16.04:xenial;14.04:trusty
使用 HTTPS 可以有效避免国内运营商的缓存劫持。
 
也可参考链接
https://mirrors.ustc.edu.cn/help/ubuntu.html
posted @ 2022-03-23 11:14  qzl  阅读(636)  评论(0编辑  收藏  举报