跳转至

02 - 系统软件源与 apt 配置 📦

前提条件 ✅

  • 已完成 Debian 12 Bookworm 最小化安装(主机名 LinuxDC,IP 192.168.1.100/24)
  • 虚拟机环境:VMware Workstation Pro(网络适配器为桥接或 NAT,已能 ping 通外网)
  • 以 root 或具有 sudo 权限的用户登录
  • 网络正常,能访问 https://mirrors.tuna.tsinghua.edu.cn 等镜像站

详细步骤 🛠️

  1. 备份原始 sources.list 🔄

    cp /etc/apt/sources.list /etc/apt/sources.list.bak-$(date +%F)
    

  2. 替换为国内高速镜像源(2026 年仍推荐清华 / 阿里 / 华为)
    清华镜像为例(速度快、更新及时、https 支持完整):

cat > /etc/apt/sources.list << 'EOF'
# Debian 12 "Bookworm" - 主源
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
#deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware

# 安全更新源
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
#deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware

# 更新源(bugfix、security backports 等)
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
#deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware

# 可选:backports(较新内核、软件包,生产谨慎启用)
#deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
EOF

其他常用镜像(可直接替换上面地址): - 阿里云:https://mirrors.aliyun.com/debian/ - 华为云:https://mirrors.huaweicloud.com/debian/ - 中科大:https://mirrors.ustc.edu.cn/debian/

  1. 更新索引并验证
    apt update
    

正常结果:所有源显示 "Hit" 或 "Get",无 404、签名错误或超时

  1. 执行全系统升级(首次强烈推荐)

    apt full-upgrade -y
    apt autoremove -y
    apt autoclean
    

  2. 安装 VMware 增强工具 & 常用基础包 🛠️

    apt install -y open-vm-tools open-vm-tools-desktop \
        vim curl wget git net-tools lsof tree htop jq unzip \
        ca-certificates apt-transport-https gnupg2 sudo apparmor-utils
    

  3. 启用并验证 open-vm-tools(VMware Workstation Pro 关键优化)

    systemctl enable --now open-vm-tools
    vmware-toolbox-cmd -v          # 确认工具版本
    

效果:更好鼠标集成、剪贴板共享、分辨率自适应、文件拖拽等

  1. 重启虚拟机确认升级效果 🔄
    reboot
    

重启后检查内核版本(升级后通常会使用最新可用内核):

uname -r

实践任务 🎯

  1. 备份并替换 sources.list 为清华镜像
  2. 执行 apt update && apt full-upgrade -y 并观察是否有错误或新内核安装
  3. 安装 open-vm-tools 并重启虚拟机,测试鼠标移动、剪贴板共享是否更流畅
  4. apt list --installed | grep open-vm-tools 确认工具已安装

自测问题 ❓

  1. 为什么生产环境优先使用国内镜像而不是官方 deb.debian.org?
  2. apt full-upgrade 相比 apt upgrade 会额外处理哪些情况?
  3. 如何临时切换回官方源进行对比测试(不破坏当前文件)?
  4. 安装 open-vm-tools 后,VMware 虚拟机最明显的 3 个使用体验提升是什么?

总结 📌

完成了 Debian 软件源的高速优化与首次全系统升级,使用国内镜像大幅缩短下载时间。
在 VMware Workstation Pro 环境下安装 open-vm-tools 是立即提升操作体验的关键步骤,为后续章节的流畅实验奠定基础。