Raspberry Pi APT Source Optimization: Switch to Tsinghua Mirrors for Faster Updates

Raspberry Pi APT Source Optimization: Switch to Tsinghua Mirrors for Faster Updates

Raspberry Pi APT Source Optimization: Switch to Tsinghua Mirrors for Faster Updates

Speed up apt update and apt upgrade on your Raspberry Pi by switching to Tsinghua University mirrors. This guide covers aarch64 architecture and Debian bookworm.

Step 1: Check Your Raspberry Pi Architecture

First, determine your system architecture:

$ uname -a

If the output contains aarch64, proceed with the following steps. This guide is for 64-bit Raspberry Pi OS (Debian bookworm).

Note: For 32-bit systems (armv7l), the mirror configuration differs slightly. This guide assumes aarch64 (64-bit).

Step 2: Configure Main APT Sources List

Edit the main sources list file:

$ sudo nano /etc/apt/sources.list

Comment out or delete all existing content, then add the following Tsinghua mirror entries for Debian bookworm:

# Default commented source mirrors to speed up apt update
deb https://mirrors4.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src https://mirrors4.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware

deb https://mirrors4.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src https://mirrors4.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware

deb https://mirrors4.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://mirrors4.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware

# Security updates
deb https://mirrors4.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src https://mirrors4.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware

Save and exit (Ctrl+O, Enter, then Ctrl+X in nano).

Step 3: Configure Raspberry Pi Specific Sources

Edit the Raspberry Pi specific sources list:

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

Comment out or delete all existing content, then add:

deb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ bookworm main

Save and exit.

Step 4: Update Package Lists and Upgrade

With the new mirror configured, run the following commands:

$ sudo apt update
$ sudo apt upgrade -y
$ sudo apt autoremove
Pro tip: The -y flag automatically answers "yes" to prompts. Remove it if you prefer to review changes before installation.

Understanding the Changes

Here's what each configuration file controls:

  • /etc/apt/sources.list — Main Debian package repositories for the base system
  • /etc/apt/sources.list.d/raspi.list — Raspberry Pi specific packages (firmware, kernel, tools)

The Tsinghua mirrors provide significantly faster download speeds for users in China compared to the default Debian and Raspberry Pi repositories.

Verification

After running sudo apt update, you should see output similar to:

Hit:1 https://mirrors4.tuna.tsinghua.edu.cn/debian bookworm InRelease
Hit:2 https://mirrors4.tuna.tsinghua.edu.cn/debian bookworm-updates InRelease
Hit:3 https://mirrors4.tuna.tsinghua.edu.cn/debian-security bookworm-security InRelease
Hit:4 https://mirrors.tuna.tsinghua.edu.cn/raspberrypi bookworm InRelease

If you encounter any errors, double-check that:

  • Your Raspberry Pi has internet connectivity
  • The mirror URLs are correctly typed (no extra spaces)
  • You're running a 64-bit OS (aarch64) for these exact URLs
Reverting changes: To restore original repositories, you can restore the backup comments or reinstall the default sources with:
sudo cp /usr/share/raspberrypi-sysconf/defaults/apt/sources.list /etc/apt/sources.list

Additional Optimization Tips

  • Consider enabling the deb-src lines only if you need source packages (they increase update time)
  • For other architectures (armv7l, i386), use the appropriate Debian mirror paths
  • Periodically run sudo apt autoremove to clean up orphaned packages


Previous post Next post

Leave a comment