备份现有源:
sudo cp /etc/apt/sources.list /etc/apt/sources.list_bak
一般情况下,将 /etc/apt/sources.list 文件中 Debian 默认的源地址 http://deb.debian.org/ 替换为国内源即可
#中国科技大学
sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
sed -i 's/security.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
#163网易云
sed -i 's/deb.debian.org/mirrors.163.com/g' /etc/apt/sources.list
sed -i 's/security.debian.org/mirrors.163.com/g' /etc/apt/sources.list
#阿里云
sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
#清华同方
sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
sed -i 's/security.debian.org/mirrors.163.com/g' /etc/apt/sources.list
更新一下系统
apt update
如果遇到无法拉取 https 源的情况,先使用 http 源并安装:
sudo apt install apt-transport-https ca-certificates
如果不是root用户,前面需要加sudo
如果源出现错误可能需要先切回官方源:(Debian10为例)
cp -r /etc/apt/sources.list /etc/apt/sources.list.bak;echo -e "deb http://deb.debian.org/debian/ buster main\ndeb-src http://deb.debian.org/debian/ buster main\ndeb http://security.debian.org/debian-security buster/updates main\ndeb-src http://security.debian.org/debian-security buster/updates main\ndeb http://deb.debian.org/debian/ buster-updates main\ndeb-src http://deb.debian.org/debian/ buster-updates main\ndeb http://archive.debian.org/debian buster-backports main" > /etc/apt/sources.list;cat /etc/apt/sources.list