树莓派 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
相关推荐
奔跑的架构师18 分钟前
[A-50]ARMv9/v8-DVFS系统架构
linux·arm开发·架构·系统架构·arm
迷途呀26 分钟前
CI/CD 自动化部署实践:让代码提交后自动上线
linux·运维·nginx·ci/cd·自动化
赴生-1 小时前
Liunx 操作系统 进程概念(上)
linux
binqian1 小时前
【linux】OpenSSH升级文档
linux·运维·网络
吴声子夜歌1 小时前
Shell编程——if条件语句
linux·运维·shell
yuzhiboyouye1 小时前
那xml对应的sql语法,列举一下
xml·数据库·sql
Dawn-bit2 小时前
Linux 运维基础扩展:跳板机、堡垒机与物理服务器全流程
linux·运维·服务器·云计算·运维开发
. . . . .2 小时前
乐观锁 vs 悲观锁
数据库·sql
新时代牛马2 小时前
Linux 定时任务:crontab、anacron 与systemd timer
linux·运维·服务器
Leo.yuan2 小时前
2026年多数据库实时同步的四种架构方案及工具推荐
数据库·架构