树莓派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
相关推荐
XH-hui13 小时前
【打靶日记】群内靶机vm1
linux·网络安全
Eric.Lee202114 小时前
ubuntu 安装 Miniconda
linux·运维·python·ubuntu·miniconda
会飞的土拨鼠呀14 小时前
通过Linux进程id找到程序路径
linux·服务器·网络
8***848215 小时前
如何在Linux中找到MySQL的安装目录
linux·运维·mysql
9***J62815 小时前
Linux下PostgreSQL-12.0安装部署详细步骤
linux·运维·postgresql
W***832016 小时前
如何在 Ubuntu 22.04 上安装 MySQL
linux·mysql·ubuntu
凌寒1117 小时前
Linux(Debain)安装Redis、数据迁移
linux·运维·服务器·redis
7***q60817 小时前
在linux(Centos)中Mysql的端口修改保姆级教程
linux·mysql·centos
用户4760220227818 小时前
机器配置免密切root
linux
zzzsde18 小时前
【Linux】基础开发工具(2):vim补充说明&&gcc/g++编译器
linux·运维·服务器