睡醒了再说 發表於 2025-9-16 00:00:00

在Windows下使用WSL安装Ubuntu并配置国内镜像的具体教程

<div id="navCategory"><h5 class="catalogue">目录</h5><ul class="first_class_ul"><li>一、启用 Windows 子系统 Linux (WSL)<ul class="second_class_ul"><li>1.1 开启 WSL 功能</li><li>1.2 启用虚拟机平台功能</li><li>1.3 安装 WSL 2</li><li>1.4 安装 Ubuntu</li></ul></li><li>二、配置国内镜像源<ul class="second_class_ul"><li>2.1 修改软件源</li><li>2.2 更新软件源</li><li>2.3 升级现有的软件包</li></ul></li><li>三、常见问题及解决<ul class="second_class_ul"><li>3.1 WSL 2 安装失败</li><li>3.2 安装软件包时出现问题</li></ul></li><li>四、总结<ul class="second_class_ul"></ul></li></ul></div><p>在 Windows 上安装并使用 Ubuntu 子系统(WSL,Windows Subsystem for Linux)是一种便捷的方式,可以让你直接在 Windows 上运行 Linux 环境。本文将介绍如何在 Windows 上安装 WSL、安装 Ubuntu,并配置国内镜像源以提高安装和更新速度。</p>
<p class="maodian"></p><h2>一、启用 Windows 子系统 Linux (WSL)</h2>
<p class="maodian"></p><h3>1.1 开启 WSL 功能</h3>
<p>首先,你需要启用 Windows 子系统 Linux 功能。按照以下步骤操作:</p>
<ul><li><strong>打开&ldquo;控制面板&rdquo;</strong>,进入&nbsp;<strong>&ldquo;程序&rdquo;</strong>&nbsp;&gt;&nbsp;<strong>&ldquo;启用或关闭 Windows 功能&rdquo;</strong>。</li><li>在弹出的窗口中,找到并勾选&nbsp;<strong>&ldquo;适用于 Linux 的 Windows 子系统 (Windows Subsystem for Linux)&rdquo;</strong>。</li><li>点击&nbsp;<strong>&ldquo;确定&rdquo;</strong>,然后等待系统完成安装。</li><li>重启计算机以使更改生效。</li></ul>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250916/2-25091611550L51.png" /></p>
<p class="maodian"></p><h3>1.2 启用虚拟机平台功能</h3>
<ul><li>在&ldquo;控制面板&rdquo;中,继续在&nbsp;<strong>&ldquo;程序&rdquo;</strong>&nbsp;&gt;&nbsp;<strong>&ldquo;启用或关闭 Windows 功能&rdquo;</strong>&nbsp;中,勾选&nbsp;<strong>&ldquo;虚拟机平台&rdquo;</strong>。</li><li>点击&nbsp;<strong>&ldquo;确定&rdquo;</strong>,并重启计算机。</li></ul>
<p class="maodian"></p><h3>1.3 安装 WSL 2</h3>
<p>WSL 2 是最新的 WSL 版本,它提供了完整的 Linux 内核支持,性能比 WSL 1 更强大。如果你希望使用 WSL 2,请按照以下步骤操作:</p>
<ul><li><strong>安装 Linux 内核更新包</strong>:从&nbsp;Microsoft 官方下载 WSL 2 内核更新包https://aka.ms/wsl2kernel并安装。</li><li><strong>设置 WSL 版本为 2</strong>:打开 PowerShell 或命令提示符,执行以下命令:</li></ul>
<div class="dxycode"><pre class="brush:bash;">wsl --set-default-version 2</pre></div>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250916/2-25091611550X13.png" /></p>
<p class="maodian"></p><h3>1.4 安装 Ubuntu</h3>
<ul><li>打开&nbsp;<strong>Microsoft Store</strong>,搜索&nbsp;<strong>Ubuntu</strong>。</li><li>选择你想要安装的 Ubuntu 版本(例如 Ubuntu 20.04 或 Ubuntu 22.04),点击&nbsp;<strong>安装</strong>。</li><li>安装完成后,点击&nbsp;<strong>启动</strong>,进行初始化设置(创建用户名和密码)。</li></ul>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250916/2-25091611550S03.png" /></p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250916/2-25091611550YJ.png" /></p>
<p class="maodian"></p><h2>二、配置国内镜像源</h2>
<p>因为国外的服务器可能会导致 Ubuntu 更新速度较慢,尤其是在中国大陆地区,推荐更改软件源为国内镜像源。</p>
<p class="maodian"></p><h3>2.1 修改软件源</h3>
<ul><li>打开 Ubuntu 终端</li><li>备份现有的源配置文件:</li></ul>
<div class="dxycode"><pre class="brush:bash;">sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup</pre></div>
<p>编辑 sources.list 文件:</p>
<div class="dxycode"><pre class="brush:bash;">sudo nano /etc/apt/sources.list</pre></div>
<p>替换现有的源为国内镜像源,例如使用 阿里云镜像源。你可以将文件内容替换为以下内容:</p>
<p>阿里云镜像源:</p>
<div class="dxycode"><pre class="brush:bash;">deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse</pre></div>
<p>清华大学镜像源:</p>
<div class="dxycode"><pre class="brush:bash;">deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse</pre></div>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250916/2-2509161155091P.png" /></p>
<p>5.保存并退出编辑器:按下 Ctrl + X,然后按 Y 保存更改,再按 Enter。</p>
<p class="maodian"></p><h3>2.2 更新软件源</h3>
<p>修改完源后,更新软件包索引以使更改生效:</p>
<div class="dxycode"><pre class="brush:bash;">sudo apt update</pre></div>
<p class="maodian"></p><h3>2.3 升级现有的软件包</h3>
<p>更新软件包到最新版本:</p>
<div class="dxycode"><pre class="brush:bash;">sudo apt upgrade</pre></div>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250916/2-250916115509263.png" /></p>
<p class="maodian"></p><h2>三、常见问题及解决</h2>
<p class="maodian"></p><h3>3.1 WSL 2 安装失败</h3>
<p>如果在安装过程中遇到问题,尝试以下操作:</p>
<p>检查 Windows 版本:确保你的 Windows 版本是 Windows 10 1903 或更高版本。</p>
<p>更新操作系统:使用 Windows Update 工具更新到最新版本。</p>
<p>启用虚拟化技术:在 BIOS 中启用虚拟化技术(Intel VT-x 或 AMD-V)。</p>
<p class="maodian"></p><h3>3.2 安装软件包时出现问题</h3>
<p>如果遇到&ldquo;无法连接到服务器&rdquo;的问题,可以尝试重新更换国内镜像源,或使用 sudo apt-get update --fix-missing 命令修复软件包。</p>
<p class="maodian"></p><h2>四、总结</h2>
<p>通过 WSL,你可以方便地在 Windows 上运行 Ubuntu 系统,并通过配置国内镜像源提高软件包下载和更新的速度。无论你是开发者、研究人员还是学习者,WSL 提供了一个强大的 Linux 环境,而无需离开 Windows 系统。</p>
<p>希望本文对你在 Windows 上安装和配置 WSL 环境有所帮助!如果你有任何问题,欢迎在评论区留言。</p>
<p>以上就是如何在 Windows 下使用 WSL 安装 Ubuntu 并配置国内镜像的详细内容,更多相关资料请阅读琼殿技术社区其它文章!</p>
頁: [1]
查看完整版本: 在Windows下使用WSL安装Ubuntu并配置国内镜像的具体教程