树莓派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
相关推荐
范桂飓2 小时前
win11 安装 WSL2 Ubuntu 并支持远程 SSH 登录
linux·ubuntu·ssh
DeeplyMind2 小时前
AMD KFD的BO设计分析系列3-4:Linux DRM GEM mmap 与 drm_vma_offset_node 机制详解
linux·drm·opengl驱动·drm_gem_object
IT成长日记3 小时前
【LVS入门宝典】LVS-TUN模式原理与配置:跨越网络界限的负载均衡解决方案
linux·网络·负载均衡·lvs·tun
IT成长日记3 小时前
【LVS入门宝典】LVS-TUN模式配置实战以及配置关键点:Real Server的路由表调整、ipip模块加载
linux·运维·服务器·lvs·tun
“αβ”3 小时前
网络编程套接字(三)---简单的TCP网络程序
linux·服务器·网络·c++·网络协议·tcp/ip·套接字
x-cmd3 小时前
[x-cmd] x-cmd 对 Xonsh 的支持
linux·运维·服务器·终端·命令行
打不了嗝 ᥬ᭄3 小时前
【Linux】网络基础
linux·运维·网络
风车带走过往4 小时前
部署开源PPTagent 生成工具
linux·开源
范桂飓5 小时前
在 Windows GPU 机器上运行 Linux CUDA
linux·运维·windows