A-A+

更换树莓派国内镜像源

2019年03月12日 经验杂谈 暂无评论 阅读 2,101 次

目前最新的系统Raspbian(2017-08-16及以后的系统)已经基于Debian 9 Stretch,请选择正确的软件源。
更换源后,需要更新本地软件索引:

sudo apt-get update
零、一键换源

直接执行以下两行命令,即可替换将官方默认软件源替换为
中科大镜像源

sudo sed -i 's#://mirrordirector.raspbian.org#s://mirrors.ustc.edu.cn/raspbian#g' /etc/apt/sources.list 
sudo sed -i 's#://archive.raspberrypi.org/debian#s://mirrors.ustc.edu.cn/archive.raspberrypi.org#g' /etc/apt/sources.list.d/raspi.list

或换为清华镜像源

sudo sed -i 's#://mirrordirector.raspbian.org#s://mirrors.tuna.tsinghua.edu.cn/raspbian#g' /etc/apt/sources.list
sudo sed -i 's#://archive.raspberrypi.org/debian#s://mirrors.tuna.tsinghua.edu.cn/raspberrypi#g' /etc/apt/sources.list.d/raspi.list

2018.05.18更新:新的默认源为raspbian.raspberrypi.org
因此一键换源相应改为

sudo sed -i 's#://raspbian.raspberrypi.org#s://mirrors.ustc.edu.cn/raspbian#g' /etc/apt/sources.list 
sudo sed -i 's#://archive.raspberrypi.org/debian#s://mirrors.ustc.edu.cn/archive.raspberrypi.org#g' /etc/apt/sources.list.d/raspi.list
或
sudo sed -i 's#://raspbian.raspberrypi.org#s://mirrors.tuna.tsinghua.edu.cn/raspbian#g' /etc/apt/sources.list
sudo sed -i 's#://archive.raspberrypi.org/debian#s://mirrors.tuna.tsinghua.edu.cn/raspberrypi#g' /etc/apt/sources.list.d/raspi.list
一、树莓派基金会提供的源

/etc/apt/sources.list.d/raspi.list里的软件源是树莓派基金会单独(非Raspbian开发者)提供/维护的软件源,主要包括raspi-configminecraftpi树莓派桌面环境内核固件驱动等少量软件。
这个软件源相关资料比较少,国内目前只有清华(201709开始提供)和中科大有提供
Stretch(三选其一即可)

中科大
deb https://mirrors.ustc.edu.cn/archive.raspberrypi.org/ stretch main ui
清华
deb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ stretch main ui
默认官方源
deb http://archive.raspberrypi.org/debian/ stretch main ui      

Jessie(三选其一即可)

中科大
deb https://mirrors.ustc.edu.cn/archive.raspberrypi.org/ jessie main ui
清华
deb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ jessie main ui
默认官方源
deb http://archive.raspberrypi.org/debian/ jessie main ui       
二、Raspbian源

raspbian这个源是由独立开发者维护的,与树莓派基金会并无直接联系。国内源比较多,选择一个与自己延迟最小或连接速度最好或物理距离最短的即可。
无需担心各个软件源内容上会有不同,基本上各个站点每天都会同步一次,绝大部分情况下某软件安装不了与用了哪个站点提供的源无关。
通常位于/etc/apt/sources.list
Stretch(选择其中一个即可,注意大小写及目录)

中科大
deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi 
清华
deb https://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
大连东软
deb http://mirrors.neusoft.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
重庆大学
deb http://mirrors.cqu.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
浙江大学
deb http://mirrors.zju.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
阿里云
deb http://mirrors.aliyun.com/raspbian/raspbian/ stretch main contrib non-free rpi 
搜狐
deb http://mirrors.sohu.com/raspbian/raspbian/ stretch main contrib non-free rpi 
元智大学(中国台湾)
deb http://ftp.cse.yzu.edu.tw/Linux/raspbian/raspbian/ stretch main contrib non-free rpi 
新加坡国立大学
deb http://mirror.nus.edu.sg/raspbian/raspbian/ stretch main contrib non-free rpi
北陆先端科学技术大学院大学(日本知名镜像站,日常出口带宽2g)
deb http://ftp.jaist.ac.jp/raspbian/ stretch main contrib non-free rpi
牛津大学
deb http://mirror.ox.ac.uk/sites/archive.raspbian.org/archive/raspbian/  stretch main contrib non-free rpi
美国Berkely大学
deb http://mirrors.ocf.berkeley.edu/raspbian/raspbian/ stretch main contrib non-free rpi
美国俄克拉荷马大学
deb http://reflection.oss.ou.edu/raspbian/raspbian/ stretch main contrib non-free rpi
南非知名软件源
deb http://mirror.liquidtelecom.com/raspbian/raspbian/ stretch main contrib non-free rpi 
默认源(带重定向by mirrorbrain)
deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi
官方源
deb https://archive.raspbian.org/raspbian/ stretch main contrib non-free rpi

Jessie(选择其中一个即可,注意大小写及目录)

中科大
deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ jessie main contrib non-free rpi 
清华
deb https://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ jessie main contrib non-free rpi
大连东软
deb http://mirrors.neusoft.edu.cn/raspbian/raspbian/ jessie main contrib non-free rpi
重庆大学
deb http://mirrors.cqu.edu.cn/raspbian/raspbian/ jessie main contrib non-free rpi
浙江大学
deb http://mirrors.zju.edu.cn/raspbian/raspbian/ jessie main contrib non-free rpi
阿里云
deb http://mirrors.aliyun.com/raspbian/raspbian/ jessie main contrib non-free rpi 
搜狐
deb http://mirrors.sohu.com/raspbian/raspbian/ jessie main contrib non-free rpi 
元智大学(中国台湾)
deb http://ftp.cse.yzu.edu.tw/Linux/raspbian/raspbian/ jessie main contrib non-free rpi 
新加坡国立大学
deb http://mirror.nus.edu.sg/raspbian/raspbian/ jessie main contrib non-free rpi
北陆先端科学技术大学院大学(日本知名镜像站,日常出口带宽2g)
deb http://ftp.jaist.ac.jp/raspbian/ jessie main contrib non-free rpi 
牛津大学
deb http://mirror.ox.ac.uk/sites/archive.raspbian.org/archive/raspbian/  jessie main contrib non-free rpi 
美国Berkely大学
deb http://mirrors.ocf.berkeley.edu/raspbian/raspbian/ jessie main contrib non-free rpi
美国俄克拉荷马大学
deb http://reflection.oss.ou.edu/raspbian/raspbian/ jessie main contrib non-free rpi
南非知名软件源
deb http://mirror.liquidtelecom.com/raspbian/raspbian/ jessie main contrib non-free rpi 
默认源(带重定向by mirrorbrain)
deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
官方源
deb https://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi

参考文章:
raspbian镜像列表https://www.raspbian.org/RaspbianMirrors

 

 

使用管理员权限(经由sudo),编辑/etc/apt/sources.list文件。参考命令行为:

$ sudo nano /etc/apt/sources.list

用#注释掉原文件内容,用以下内容取代:

deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi

使用管理员权限(经由sudo),编辑/etc/apt/sources.list.d/raspi.list文件。参考命令行为:

$ sudo nano /etc/apt/sources.list.d/raspi.list

用#注释掉原文件内容,用以下内容取代:

deb http://mirror.tuna.tsinghua.edu.cn/raspberrypi/ stretch main ui
deb-src http://mirror.tuna.tsinghua.edu.cn/raspberrypi/ stretch main ui

注意: 网址末尾的raspbian重复两次是必须的。因为Raspbian的仓库中除了APT软件源还包含其他代码。APT软件源不在仓库的根目录,而在raspbian/子目录下。

编辑镜像站后,请使用sudo apt-get update命令,更新软件源列表,同时检查您的编辑是否正确。

使用HTTPS可以有效避免国内运营商的缓存劫持,但需要事先安装apt-transport-https

给我留言