<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>qiuxiuyaのBlog</title>
  
  
  <link href="https://blog.39o.top/atom.xml" rel="self"/>
  
  <link href="https://blog.39o.top/"/>
  <updated>2026-04-20T14:53:52.097Z</updated>
  <id>https://blog.39o.top/</id>
  
  <author>
    <name>qiuxiuya</name>
    
  </author>
  
  <generator uri="https://hexo.io/">Hexo</generator>
  
  <entry>
    <title>如何在windows上安装wsl2开发环境</title>
    <link href="https://blog.39o.top/2026/04/20/wsl/"/>
    <id>https://blog.39o.top/2026/04/20/wsl/</id>
    <published>2026-04-20T12:29:41.000Z</published>
    <updated>2026-04-20T14:53:52.097Z</updated>
    
    <content type="html"><![CDATA[<h4 id="多图警告"><a href="#多图警告" class="headerlink" title="多图警告"></a><strong>多图警告</strong></h4><h3 id="·引言"><a href="#·引言" class="headerlink" title="·引言"></a><strong>·引言</strong></h3><details><summary>众所周知在Windows上开发会有很多奇奇怪怪的问题</summary>&nbsp;&nbsp;&nbsp;·超级难配的环境<br>&nbsp;&nbsp;&nbsp;·神秘的路径<br>&nbsp;&nbsp;&nbsp;·编译器对Unicode支持不好</details><p>但装双系统&#x2F;虚拟机又比较不方便,有什么在windows上开发又比较优雅的方法呢，答案就是wsl2 即 <a href="https://learn.microsoft.com/zh-cn/windows/wsl/about">Windows Subsystem for Linux</a></p><h2 id="·-安装"><a href="#·-安装" class="headerlink" title="· 安装"></a><strong>· 安装</strong></h2><p><strong>TIPS:</strong> 请先确保你的电脑已开启虚拟化(可在任务管理器-性能-cpu查看)，若未开启，请自行搜索在bios中开启</p><p><img src="https://img.39o.top/file/1776595371914_image.png" alt="image.png"></p><h4 id="1-首先以管理员身份打开cmd-powershell-输入wsl-install"><a href="#1-首先以管理员身份打开cmd-powershell-输入wsl-install" class="headerlink" title="1,首先以管理员身份打开cmd&#x2F;powershell,输入wsl --install"></a>1,首先以管理员身份打开cmd&#x2F;powershell,输入<code>wsl --install</code></h4><p>windows便会自动下载wsl环境，当安装完成后，重启电脑</p><h4 id="2-安装所需的linux发行版-以Debian为例"><a href="#2-安装所需的linux发行版-以Debian为例" class="headerlink" title="2,安装所需的linux发行版(以Debian为例)"></a>2,安装所需的linux发行版(以Debian为例)</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wsl --install Debian</span><br></pre></td></tr></table></figure><p>需要其他发行版可通过<code>wsl --list --online</code>查看安装</p><p><img src="https://img.39o.top/file/1776596059687_image.png" alt="image.png"><br>安装完成后，会要求你设置Linux的用户名和密码<br><img src="https://img.39o.top/file/1776596120216_image.png" alt="image.png"><br>设置完成后便会自动进入熟悉的Debian啦</p><h2 id="·-安装环境"><a href="#·-安装环境" class="headerlink" title="· 安装环境"></a><strong>· 安装环境</strong></h2><h4 id="1-root权限"><a href="#1-root权限" class="headerlink" title="1,root权限"></a>1,root权限</h4><p>由于wls的默认用户并没有root权限，图方便就先<code>sudo su</code>取得权限<br><img src="https://img.39o.top/file/1776596428727_image.png" alt="image.png"><br>在这里输入刚刚设置的密码，就进入了root用户模式</p><h4 id="2-更换软件源"><a href="#2-更换软件源" class="headerlink" title="2,更换软件源"></a>2,更换软件源</h4><p>默认的debian官方镜像源国内方向并不大友好，所以切换为国内阿里云源</p><p><strong>TIPS:</strong> 由于默认并没有安装<code>ca-certificates</code>，所以如果替换其他源，请使用http而非<strong>https</strong></p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">cat &gt;</span><br><span class="line">deb http://mirrors.aliyun.com/debian/ trixie main</span><br><span class="line">deb http://mirrors.aliyun.com/debian/ trixie-updates main</span><br><span class="line">deb http://mirrors.aliyun.com/debian/ trixie-backports main</span><br><span class="line">EOF</span><br></pre></td></tr></table></figure><p>更新软件源</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">apt update</span><br></pre></td></tr></table></figure><h4 id="3-安装常用环境"><a href="#3-安装常用环境" class="headerlink" title="3,安装常用环境"></a>3,安装常用环境</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">apt install gdb build-essential python3 python3-pip git -y</span><br></pre></td></tr></table></figure><p>此处按自己需要，这里安装了C&#x2F;C++&amp;Python</p><h2 id="·-vscode梦幻联动"><a href="#·-vscode梦幻联动" class="headerlink" title="· vscode梦幻联动"></a><strong>· vscode梦幻联动</strong></h2><h3 id="1-安装vscode-wsl扩展"><a href="#1-安装vscode-wsl扩展" class="headerlink" title="1,安装vscode wsl扩展"></a>1,安装vscode wsl扩展</h3><p>在vscode扩展搜索<code>ms-vscode-remote.remote-wsl</code>并安装<img src="https://img.39o.top/file/1776597262225_image.png" alt="image.png"><br>安装完成后便可以在左侧远程资源管理器处看到wsl了<br><img src="https://img.39o.top/file/1776597464613_image.png" alt="image.png"><br>点击连接后，可以看到左下角已经显示连接到远程显示的是wsl:Debian了<br><img src="https://img.39o.top/file/1776597603514_image.png" alt="image.png"></p><h3 id="2-替换vscode默认终端"><a href="#2-替换vscode默认终端" class="headerlink" title="2,替换vscode默认终端"></a>2,替换vscode默认终端</h3><p>使用 <code>ctrl+,</code>打开设置，搜索<code>terminal.integrated.defaultProfile.windows</code>,修改为wsl即可</p><p><img src="https://img.39o.top/file/1776598020253_image.png" alt="image.png"></p><h3 id="3-vscode-wsl联动的两种方法"><a href="#3-vscode-wsl联动的两种方法" class="headerlink" title="3,vscode&amp;wsl联动的两种方法"></a>3,vscode&amp;wsl联动的两种方法</h3><p>（1）从vscode调用wsl: 同上，在左侧远程资源管理器处点击连接</p><p>（2）从wsl打开vscode: 在wsl中目录输入  <code>code .</code> 后vscode便会打开到该文件夹(处于非root用户模式)</p><h3 id="4-路径的相互映射"><a href="#4-路径的相互映射" class="headerlink" title="4,路径的相互映射"></a>4,路径的相互映射</h3><p>windows文件在wsl默认映射在 <code> /mnt/</code> 中<br>wsl文件在windows可以通过资源管理器打开<code>\\wsl$\</code>读取</p><p><strong>TIPS:</strong> 若要从windows修改wsl文件，需要在wsl中编辑 <code>/etc/wsl.conf</code>，加入</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[automount]</span><br><span class="line">enabled = true</span><br><span class="line">metadata = true</span><br></pre></td></tr></table></figure><p>在cmd&#x2F;powershell执行</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wsl --shutdown</span><br></pre></td></tr></table></figure><p>重启wsl即可</p><h3 id="5-vscode环境配置"><a href="#5-vscode环境配置" class="headerlink" title="5,vscode环境配置"></a>5,vscode环境配置</h3><p>由于wsl插件环境也独立于windows，所以在连接上wsl后，vscode的插件得重新安装，连接上wsl，打开插件列表，点击在wsl安装即可<br><img src="https://img.39o.top/file/1776679527509_image.png" alt="image.png"></p>]]></content>
    
    
    <summary type="html">233</summary>
    
    
    
    
    <category term="折腾" scheme="https://blog.39o.top/tags/%E6%8A%98%E8%85%BE/"/>
    
  </entry>
  
</feed>
