windows下安装linux-ubuntu系统文章目录windows下安装linux-ubuntu系统1.安装指引文件2.安装步骤步骤 1 - 启用适用于 Linux 的 Windows 子系统步骤2 -启用虚拟机功步骤3-指定安装源包3.查看是否安装成功4.启动子系统设置为默认子系统后直接启动5.添加快捷键6.修改下载地址第一步备份原始软件源配置第二步编辑软件源配置文件第三步替换为国内镜像源选项 A阿里云镜像源推荐稳定性高CDN覆盖广选项 B清华大学镜像源推荐教育网及北方用户速度快支持HTTPS第四步保存并退出第五步更新软件包索引并升级系统常见问题排查1.安装指引文件官方文件 https://learn.microsoft.com/zh-cn/windows/wsl/install-manual 参考雷丰阳老师视频 https://www.bilibili.com/video/BV19z421Y7Nn/?spm_id_from333.1391.0.0离线安装linux-ubuntu下载资源清华源 https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/ 稳定版本 24.04.4/---》ubuntu-24.04.4-wsl-amd64.wsl进行下载2.安装步骤前提电脑支持虚拟化相关虚拟服务开启提前说下windows更新要开启状态不然在线安装时拒绝更新。后来与和官网不同是离线安装指定的安装包我这边是wsl版本1安装的也成功了官网要wsl2我的初衷是不让默认安装c盘指定安装空闲的磁盘步骤如下步骤 1 - 启用适用于 Linux 的 Windows 子系统以管理员身份打开 PowerShell PowerShell 右键单击 以管理员身份运行并输入以下命令dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart步骤2 -启用虚拟机功以管理员身份打开 PowerShell 并运行dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart步骤3-指定安装源包镜像文件是提前下载好的上面提供清华源地址# 语法wsl --import 发行版名称 安装路径 镜像文件路径 wsl --import Ubuntu-22.04 D:\WSL\Ubuntu-22.04 G:\WSL\ubuntu-22.04.5-wsl-amd64.wsl3.查看是否安装成功wsl --list --verbose # 或者简写为 wsl -l -v如图展示NAME STATE VERSIONUbuntu-22.04 Stopped 2Debian Running 24.启动子系统wsl -d Ubuntu-22.04设置为默认子系统后直接启动# 设置默认发行版 wsl --set-default Ubuntu-22.04 # 之后只需输入 wsl 即可启动 wsl # 彻底关闭所有 WSL wsl --shutdown5.添加快捷键‌桌面直接创建快捷方式‌右键桌面→新建→快捷方式位置栏输入命令替换为你的发行版名C:\Windows\System32\wsl.exe -d Ubuntu-22.04命名后完成创建还可右键属性自定义图标和快捷键。‌添加到开始菜单‌将生成的快捷方式移动到C:\ProgramData\Microsoft\Windows\Start Menu\Programs目录就能在开始菜单直接找到该子系统入口。6.修改下载地址第一步备份原始软件源配置在修改任何系统配置文件前务必进行备份以便出错时恢复。sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak第二步编辑软件源配置文件使用文本编辑器如nano或vim打开源列表文件。对于新手推荐使用nano a操作更直观。sudo nano /etc/apt/sources.list第三步替换为国内镜像源选项 A阿里云镜像源推荐稳定性高CDN覆盖广deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse选项 B清华大学镜像源推荐教育网及北方用户速度快支持HTTPSdeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse‌注意‌jammy是 Ubuntu 22.04 的代号请勿修改为其他版本代号否则会导致源不可用。第四步保存并退出如果使用 ‌nano‌按Ctrl O确认保存然后按Enter确认文件名最后按Ctrl X退出编辑器。如果使用 ‌vim‌按Esc键输入:wq然后按Enter保存退出。第五步更新软件包索引并升级系统替换源之后必须刷新本地的软件包缓存使新源生效然后执行系统升级。‌刷新索引‌这一步会验证新源是否连通sudo apt update若看到类似Hit:1 http://mirrors.aliyun.com/ubuntu jammy InRelease的输出且无报错说明换源成功。‌执行升级‌根据本地最新的索引对比已安装的软件下载并安装新版本。sudo apt upgrade此过程可能会下载并安装数百个安全补丁和内核更新耗时取决于服务器带宽请耐心等待直至完成。‌清理无用依赖‌可选释放磁盘空间sudo apt autoremove -y常见问题排查‌GPG 密钥错误‌如果apt update报错提示 NO_PUBKEY 或 GPG 错误通常是因为 HTTPS 源需要证书或密钥未同步。尝试执行sudo apt install ca-certificates后再试或者检查是否误删了/etc/apt/trusted.gpg.d/下的文件。‌网络连接失败‌如果 ping 不通镜像源域名请检查服务器的 DNS 配置可临时修改/etc/resolv.conf添加nameserver 8.8.8.8或nameserver 114.114.114.114。