树莓派4B+ubuntu20.04设置国内源

步骤一:备份原始源列表

bash 复制代码
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.bak

步骤二:更换主软件包源

请根据你的系统架构(通常是 aarch64/ARM64)进行修改。

  1. 编辑主源列表文件:

    bash 复制代码
    sudo nano /etc/apt/sources.list
  2. 注释或删除原有内容,替换为清华源:

    将文件内的所有内容替换为以下内容。确保使用的aarch64 架构:

    bash 复制代码
    # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
    
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
    
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
    
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse
    
    # 预发布软件源,不建议启用
    # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse

    关键点:

    • 树莓派是 ARM 架构,所以必须使用 ubuntu-ports 而不是普通的 ubuntu

    • URL 中的 focal 代表 Ubuntu 20.04 的代号。

步骤三:更换树莓派专用源

这个源包含一些树莓派的特定软件和内核更新。

  1. 编辑树莓派源列表文件:

    bash 复制代码
    sudo nano /etc/apt/sources.list.d/raspi.list
  2. 将其内容替换为清华镜像的树莓派源:

    bash 复制代码
    deb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ focal main

    注意: 如果此文件原本是空的或者只有注释行,直接添加上面这一行即可。

步骤四:更新软件包列表

执行以下命令,让修改后的源生效。

bash 复制代码
# 更新软件包列表
sudo apt update

# 升级所有可升级的软件包(可选,但推荐)
sudo apt upgrade

如果 sudo apt update 命令执行过程中没有出现错误,并且下载链接显示来自 mirrors.tuna.tsinghua.edu.cn,就说明换源成功了。

bash 复制代码
命中:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports focal InRelease
命中:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports focal-updates InRelease
命中:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports focal-backports InRelease
命中:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports focal-security InRelease
获取:5 https://mirrors.tuna.tsinghua.edu.cn/raspberrypi focal InRelease [6,361 B]
...

常见问题与解决

  • 错误:Certificate verification failed: The certificate is NOT trusted.

    • 原因: 系统时间不正确或 CA 证书有问题。

    • 解决: 首先确保系统时间正确。如果时间正确,可以尝试安装正确的证书:

      bash 复制代码
      sudo apt install ca-certificates
  • 错误:404 Not Found [IP: ...]

    • 原因: 源地址拼写错误,或者该镜像站暂时没有某个特定的软件包版本。

    • 解决: 仔细检查你在 sources.list 中输入的 URL 是否正确。偶尔的 404 错误可以忽略,如果大量出现,可以暂时换回官方源或尝试其他国内源(如中科大源)。

  • 如何换回官方源或其他源?

    • 使用之前备份的文件恢复即可:

      bash 复制代码
      sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list
      sudo cp /etc/apt/sources.list.d/raspi.list.bak /etc/apt/sources.list.d/raspi.list
      sudo apt update

如果你觉得清华源速度不理想,也可以尝试中国科学技术大学(USTC)源阿里云源。只需将上面步骤中的 URL 替换掉即可。

更新一些报错的解决方法

**报错:**the repository 'http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu focal InRelease' is no longer signed.

解决方法:

1. 删除旧的密钥

sudo apt-key del 421C365BD9FF1F717815A3895523BAEEB01FA116

2. 下载并添加新的密钥

sudo apt update

sudo apt install curl

curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

3. 或者直接从 ROS 官网下载密钥

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

4. 更新软件包列表

sudo apt update

修复后验证是否成功:

bash 复制代码
# 检查更新是否成功
sudo apt update

# 检查 ROS 相关的包是否可安装
apt-cache search ros-foxy
相关推荐
毒爪的小新24 分钟前
Linux 环境极速部署 vLLM:从零搭建生产级大模型推理服务
linux·人工智能·ai·语言模型·vllm
鹤落晴春31 分钟前
RH124问答3:从命令行管理文件
linux·运维·服务器
凡人叶枫36 分钟前
Effective C++ 条款30:透彻了解 inlining 的里里外外
linux·开发语言·c++·嵌入式开发·effective c++
Net_Walke2 小时前
【Linux系统】静态链接库与动态链接库
linux·嵌入式硬件
syc78901232 小时前
中文语境下AI编码工具实战对比:从迭代体验看日常开发选择
linux·人工智能·ubuntu
凡人叶枫2 小时前
Effective C++ 条款22:将成员变量声明为 private
linux·开发语言·c++
vsropy4 小时前
Ubuntu网络图标消失问题/有网络问号
linux·运维·ubuntu
coderwu4 小时前
Ubuntu 24.04 终端输入 openclaw config 提示未找到命令解决办法
linux·运维·ubuntu
凡人叶枫6 小时前
Effective C++ 条款28:避免使用 handles 指向对象内部
linux·服务器·开发语言·c++·嵌入式开发
AI帮小忙6 小时前
Debian系linux操作系统里安装OpenClaw
linux·运维·debian