当前位置: 首页 > 工具软件 > Tencent APT > 使用案例 >

为树莓派一键更换国内apt镜像源

公孙威
2023-12-01

关于如何为树莓派启用root系统并开启ssh登录,可参考之前的文章

  • 为什么要使用国内镜像源?
    树莓派官方raspbian系统默认设置软件源为
    http://raspbian.raspberrypi.org/raspbian/http://archive.raspberrypi.org/debian/,这两个网站在国内通常连接缓慢,影响使用体验。
  • 如何更换国内源?
    raspbian系统的apt软件源由/etc/apt/sources.list和/etc/apt/sources.list.d/raspi.list两个文件设定,只需更改两个文件内的记录即可。
  • 国内源那么多,该选哪一个呢?

国内支持raspbian的软件源(不完全统计,欢迎补充):

https://mirrors.cloud.tencent.com/raspbian/raspbian/
https://mirrors.cloud.tencent.com/raspberrypi/

https://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/
https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/

https://mirrors.sjtug.sjtu.edu.cn/raspbian/raspbian/
https://mirrors.sjtug.sjtu.edu.cn/raspberrypi/debian/

https://mirrors.ustc.edu.cn/raspbian/raspbian/
https://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian/

https://mirrors.aliyun.com/raspbian/raspbian/

http://mirrors.zju.edu.cn/raspbian/raspbian/

http://mirrors.neusoft.edu.cn/raspbian/raspbian/

https://mirrors.cqu.edu.cn/raspbian/raspbian/

  • 为避免误更换为无效的源,先对配置文件在同目录进行备份:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.save
sudo cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.save
  • 如需还原应执行:
sudo cp /etc/apt/sources.list.save /etc/apt/sources.list
sudo cp /etc/apt/sources.list.d/raspi.list.save /etc/apt/sources.list.d/raspi.list
  • 下面即可通过sed命令修改配置文件

上海交通大学SJTUG软件源

 sudo sed -i "s?http://raspbian.raspberrypi.org/raspbian/?https://mirrors.sjtug.sjtu.edu.cn/raspbian/raspbian/?g" /etc/apt/sources.list
 sudo sed -i "s?http://archive.raspberrypi.org/debian/?https://mirrors.sjtug.sjtu.edu.cn/raspberrypi/debian/?g" /etc/apt/sources.list.d/raspi.list

腾讯软件源

 sudo sed -i "s?http://raspbian.raspberrypi.org/raspbian/?https://mirrors.cloud.tencent.com/raspbian/raspbian/?g" /etc/apt/sources.list
 sudo sed -i "s?http://archive.raspberrypi.org/debian/?https://mirrors.cloud.tencent.com/raspberrypi/?g" /etc/apt/sources.list.d/raspi.list

清华大学开源软件镜像站TUNA

 sudo sed -i "s?http://raspbian.raspberrypi.org/raspbian/?https://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/?g" /etc/apt/sources.list
 sudo sed -i "s?http://archive.raspberrypi.org/debian/?https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/?g" /etc/apt/sources.list.d/raspi.list

中国科学技术大学开源软件镜像

 sudo sed -i "s?http://raspbian.raspberrypi.org/raspbian/?https://mirrors.ustc.edu.cn/raspbian/raspbian/?g" /etc/apt/sources.list
 sudo sed -i "s?http://archive.raspberrypi.org/debian/?https://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian/?g" /etc/apt/sources.list.d/raspi.list

其他为提供raspberrypi存储库的源未写成一键脚本。

  • 修改完成后即可使用apt进行软件包升级
 sudo apt update
 sudo apt upgrade
 类似资料: