使用国内源加速您的 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
手动修改
如果您想手动修改,请按照以下步骤操作:
- 打开终端命令行模式
- 备份
/etc/apt/sources.list文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
- 编辑apt源配置文件,使用文本编辑器打开/etc/apt/sources.list文件:
sudo nano /etc/apt/sources.list
- 在打开的文件中,将原始的apt源地址替换为本站的源地址。以下是本站的源地址示例,你可以根据自己的地理位置选择合适的源地址:
- trixie (13)
- bookworm (12)
# 本站的源地址
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
# 本站的源地址
deb http://mirrors.pidoc.cn/debian bookworm main contrib non-free non-free-firmware
deb http://mirrors.pidoc.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb http://mirrors.pidoc.cn/debian bookworm-updates main contrib non-free non-free-firmware
# 默认的树莓派源注释掉或删除
# deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
# deb http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
# deb http://deb.debian.org/debian bookworm-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 bookworm main contrib non-free non-free-firmware
#deb-src http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
#deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
-
保存并关闭文件。在nano编辑器中,按下Ctrl + X,然后按下Y确认保存,最后按下Enter退出编辑器。
-
用同样方法备份与编辑
/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
- 编辑后如下所示
- trixie (13)
- bookworm (12)
# 本站的源地址
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
# 本站的源地址
deb http://mirrors.pidoc.cn/raspberrypi/ bookworm main
# 注释掉下面一行
# deb http://archive.raspberrypi.com/debian/ bookworm main
# 以下不用改
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
# deb-src http://archive.raspberrypi.com/debian/ bookworm main
- 更新apt源列表,以使更改生效:
sudo apt update