跳到主要内容

使用国内源加速您的 APT

注意

本文档适用于 Raspberry Pi OS 的 Trixie(13)/Bookworm(12) 版本。

快速实施

使用本站作为镜像源,对两个文件进行替换

  • /etc/apt/sources.list:将其中的 deb.debian.org 替换为 mirrors.pidoc.cn
  • /etc/apt/sources.list.d/raspi.list:将其中的 archive.raspberrypi.com/debian/ 替换为 mirrors.pidoc.cn/raspberrypi/

适合于新手首次操作,只需要复制并执行以下命令即可。

sudo sed 's/deb.debian.org/mirrors.pidoc.cn/g' /etc/apt/sources.list -i
sudo sed 's/archive.raspberrypi.com\/debian\//mirrors.pidoc.cn\/raspberrypi\//g' /etc/apt/sources.list.d/raspi.list -i
sudo apt update

手动修改

如果您想手动修改,请按照以下步骤操作:

  1. 打开终端命令行模式
  2. 备份 /etc/apt/sources.list 文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  1. 编辑apt源配置文件,使用文本编辑器打开/etc/apt/sources.list文件:
sudo nano /etc/apt/sources.list
  1. 在打开的文件中,将原始的apt源地址替换为本站的源地址。以下是本站的源地址示例,你可以根据自己的地理位置选择合适的源地址:
# 本站的源地址
deb http://mirrors.pidoc.cn/debian trixie main contrib non-free non-free-firmware
deb http://mirrors.pidoc.cn/debian-security/ trixie-security main contrib non-free non-free-firmware
deb http://mirrors.pidoc.cn/debian trixie-updates main contrib non-free non-free-firmware

# 默认的树莓派源注释掉或删除
# deb http://deb.debian.org/debian trixie main contrib non-free non-free-firmware
# deb http://deb.debian.org/debian-security/ trixie-security main contrib non-free non-free-firmware
# deb http://deb.debian.org/debian trixie-updates main contrib non-free non-free-firmware

# 以下不用改
# Uncomment deb-src lines below then 'apt-get update' to enable 'apt-get source'
#deb-src http://deb.debian.org/debian trixie main contrib non-free non-free-firmware
#deb-src http://deb.debian.org/debian-security/ trixie-security main contrib non-free non-free-firmware
#deb-src http://deb.debian.org/debian trixie-updates main contrib non-free non-free-firmware
  1. 保存并关闭文件。在nano编辑器中,按下Ctrl + X,然后按下Y确认保存,最后按下Enter退出编辑器。

  2. 用同样方法备份与编辑 /etc/apt/sources.list.d/raspi.list

sudo cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.bak
sudo nano /etc/apt/sources.list.d/raspi.list
  1. 编辑后如下所示
# 本站的源地址
deb http://mirrors.pidoc.cn/raspberrypi/ trixie main
# 注释掉下面一行
# deb http://archive.raspberrypi.com/debian/ trixie main

# 以下不用改
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
# deb-src http://archive.raspberrypi.com/debian/ trixie main
  1. 更新apt源列表,以使更改生效:
sudo apt update

各种开放源地址

名称源地址
本站http://mirrors.pidoc.cn
阿里云http://mirrors.aliyun.com
腾讯云http://mirrors.cloud.tencent.com

中文翻译版以英文版相同知识授权方式共享:CC-BY-SA 4.0。交流 Q群:498908352