树莓派 Ubuntu 24.04 开机换源总结

1. 图形界面 (桌面版)

如果你刷的是 Ubuntu Desktop 24.04

  1. 打开 Software & Updates(软件和更新)

  2. Ubuntu Software 标签里找到 Download from 下拉菜单。

  3. 默认只有 Main serverServer for China,如果想要更多选择:

    bash 复制代码
    sudo apt install software-properties-gtk

    安装后再打开 → 选择 Other...Select Best Server 或手动挑镜像站。

  4. 关闭后点 Reload ,等价于执行 sudo apt update


2. 命令行方式 (推荐,最稳定)

直接修改源列表文件:

bash 复制代码
sudo nano /etc/apt/sources.list

替换为 清华源 (TUNA)

复制代码
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-security main restricted universe multiverse

替换为 阿里源

复制代码
deb http://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse

替换为 官方源

复制代码
deb http://archive.ubuntu.com/ubuntu/ noble main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ noble-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ noble-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse

保存退出,然后:

bash 复制代码
sudo apt clean
sudo apt update

3. 自动化脚本 (一键换源)

如果想开机后马上自动换成国内源,可以写 systemd 脚本。

  1. 创建脚本:
bash 复制代码
sudo nano /usr/local/bin/change-sources.sh

内容:

bash 复制代码
#!/bin/bash
SOURCE_FILE="/etc/apt/sources.list"
cat > $SOURCE_FILE <<EOF
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-security main restricted universe multiverse
EOF

apt clean
apt update
  1. 给权限:
bash 复制代码
sudo chmod +x /usr/local/bin/change-sources.sh
  1. 创建 systemd 服务:
bash 复制代码
sudo nano /etc/systemd/system/change-sources.service

内容:

复制代码
[Unit]
Description=Change APT sources to TUNA mirror at boot
After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/change-sources.sh

[Install]
WantedBy=multi-user.target
  1. 启用:
bash 复制代码
sudo systemctl daemon-reload
sudo systemctl enable change-sources.service

这样以后 每次开机都会自动把源改好并更新


总结

  • 桌面用户 :可以用 Software & Updates GUI 改源。
  • 推荐方法 :直接手动改 /etc/apt/sources.list,换成清华/阿里/中科大镜像。
  • 完全自动化 :写 systemd 脚本,开机时自动换源 + apt update

在树莓派(Raspberry Pi OS 或 Ubuntu 24.04 for Raspberry Pi)上使能 SSH 有两种常见办法:


🔌 方法一:无显示器(Headless 模式,推荐)

  1. 把系统镜像写入 TF/SD 卡后,不要直接插树莓派,先把 SD 卡插回电脑。

  2. 打开 boot 分区(Windows 下会自动显示为一个盘符)。

  3. boot 根目录里,新建一个名为 ssh 的空文件(没有扩展名)。

    • Windows:右键新建 → 文本文档 → 命名为 ssh → 删除 .txt

    • Linux/macOS:

      bash 复制代码
      cd /media/$USER/boot
      touch ssh
  4. 把 SD 卡插回树莓派并启动,SSH 服务会自动启用。

  5. 在同一局域网电脑上,用下面命令登录:

    bash 复制代码
    ssh ubuntu@raspberrypi.local
    # 或者用树莓派的 IP 地址
    ssh ubuntu@192.168.x.x

    Ubuntu 默认用户名是 ubuntu,密码是 ubuntu(首次登录会要求你修改密码)。

    Raspberry Pi OS 默认用户名是 pi,密码是 raspberry


🖥️ 方法二:有显示器和键盘时

  1. 开机后进入系统。

  2. 运行配置工具:

    • Raspberry Pi OS

      bash 复制代码
      sudo raspi-config

      进入 Interface Options → SSH → Enable

    • Ubuntu (24.04)

      先安装 OpenSSH:

      bash 复制代码
      sudo apt update
      sudo apt install openssh-server -y

      然后启用服务:

      bash 复制代码
      sudo systemctl enable ssh
      sudo systemctl start ssh
      sudo systemctl status ssh

      显示 active (running) 就成功了。


🧪 测试

在另一台电脑上执行:

bash 复制代码
ssh 用户名@树莓派_IP

例如:

bash 复制代码
ssh ubuntu@192.168.1.100

✅ 总结:

  • 没显示器 → 在 boot 分区新建 ssh 文件。
  • 有显示器 → 安装 openssh-server 并用 systemctl enable/start ssh
相关推荐
老黄编程几秒前
大型工地实时数据处理与三维重构系统方案
人工智能·ubuntu·信息可视化·重构·入侵检测·大型数据集中处理
浪客灿心6 分钟前
Linux网络传输层协议
linux·运维·网络
belldeep20 分钟前
本草纲目:如何应用 PostgreSQL 实现【中医药】主题数据库 ?
数据库·postgresql·本草纲目
Bert.Cai32 分钟前
MySQL CURTIME()函数详解
数据库·mysql
Bert.Cai33 分钟前
MySQL CURDATE()函数详解
数据库·mysql
舟遥遥娓飘飘33 分钟前
Nexus4CC 手机电脑同步claude code对话部署教程(基于linux系统)
linux·智能手机·电脑
05候补工程师38 分钟前
【ROS 2 具身智能】Gazebo 仿真避坑指南:从“幽灵机器人”到传感器数据流打通
人工智能·经验分享·笔记·ubuntu·机器人
NGSI vimp1 小时前
MySQL|MySQL 中 `DATE_FORMAT()` 函数的使用
数据库·mysql
何妨呀~1 小时前
Firewalld防火墙端口配置
linux
切糕师学AI1 小时前
Vim 深度解析:从经典 vi 到现代编辑器之巅
linux·vim·文本编辑器