树莓派 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
相关推荐
阿华田5126 小时前
重试框架 -- Guava Retry
数据库
weixin_468466856 小时前
树莓派32位与64位系统安装teamviewer远程软件
linux·单片机·自动化·树莓派·远程控制·vnc·teamviewer
挨踢攻城6 小时前
Linux 应急响应实操 Checklist
linux·运维·linux命令·rhce·rhca·厦门微思网络·linux 应急响应
柠檬汁Dev6 小时前
还在等DBA给你库?我3分钟就拉起一个高可用集群
数据库·云计算·dba
optiz6 小时前
细菌基因组genome二代测序数据分析
linux·运维·服务器
安卓开发者6 小时前
鸿蒙NEXT应用数据持久化全面解析:从用户首选项到分布式数据库
数据库·分布式·harmonyos
李游Leo7 小时前
LaTeX TeX Live 安装与 CTAN 国内镜像配置(Windows / macOS / Linux 全流程)
linux·windows·macos
蓝纹绿茶7 小时前
Python程序使用了Ffmpeg,结束程序后,文件夹中仍然生成音频、视频文件
python·ubuntu·ffmpeg·音视频
IT成长日记7 小时前
【Linux基础】Linux系统管理:GPT分区实践详细操作指南
linux·运维·服务器·gpt·parted·磁盘分区·fdisk