树莓派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
相关推荐
程序猿编码13 小时前
一个授予普通进程ROOT权限的Linux内核级后门:原理与实现深度解析
linux·运维·服务器·内核·root权限
小夏子_riotous13 小时前
openstack的使用——9. 密钥管理服务Barbican
linux·运维·服务器·系统架构·centos·云计算·openstack
六点的晨曦14 小时前
VMware安装Ubuntu的记录
linux·ubuntu
w61001046614 小时前
CKA-2026-Service
linux·服务器·网络·service·cka
HXQ_晴天14 小时前
castor什么时候已有的 .cdh 数据可以直接用,不需要重新从 root 转换?
linux
Mapleay15 小时前
Ubuntu 源的重要性!之 libgmp-dev 无法安装
linux·服务器·windows
Benszen15 小时前
Linux容器:轻量级虚拟化革命
java·linux·运维
念恒1230616 小时前
Linux初识
linux·服务器·c++
开开心心就好16 小时前
能把网页藏在Word里的实用摸鱼工具
linux·运维·服务器·windows·随机森林·逻辑回归·excel
Lucis__16 小时前
Linux网络:基于协议栈原理实现UDP通信
linux·网络·udp