宋宇宏 發表於 2024-6-29 16:00:03

Windows上安装WSL+Ubuntu来运行Linux环境

<div id="navCategory"><h5 class="catalogue">目录</h5><ul class="first_class_ul"><li><a href="#_label0">一、安装WSL</a></li><ul class="second_class_ul"><li><a href="#_lab2_0_0">1、使用图像界面</a></li><li><a href="#_lab2_0_1">2、内核安装</a></li></ul><li><a href="#_label1">二、安装ubuntu</a></li><ul class="second_class_ul"></ul><li><a href="#_label2">三、ubuntu简单配置</a></li><ul class="second_class_ul"></ul><li><a href="#_label3">四、总结</a></li><ul class="second_class_ul"></ul></ul></div><p class="maodian"><a name="_label0"></a></p><h2>一、安装WSL</h2>
<p>可以参考官网内容</p>
<p class="maodian"><a name="_lab2_0_0"></a></p><h3>1、使用图像界面</h3>
<p>打开控制面板(win+r输入control)-&gt;程序和功能-&gt;打开或关闭Windows功能-&gt;选择&ldquo;适用于Linux的Windows子系统&rdquo;与 &ldquo;虚拟机平台&rdquo;与&ldquo;Hyper-V&quot;-&gt;重启<br />&nbsp;</p>
<p style="text-align:center"><img alt="image" height="1177" src="https://img.jbzj.com/file_images/article/202406/2024629154535937.png" width="2124" /></p>
<p class="maodian"><a name="_lab2_0_1"></a></p><h3>2、内核安装</h3>
<p>WIN开始-&gt;windows powershell-&gt;以管理员方式运行</p>
<p>执行安装</p>
<div class="jb51code"><pre class="brush:bash;">wsl --install</pre></div>
<p style="text-align:center"><img alt="image" height="799" src="https://img.jbzj.com/file_images/article/202406/2024629154535938.png" width="1200" /></p>
<p>查看wsl版本</p>
<div class="jb51code"><pre class="brush:bash;">wsl -l -v</pre></div>
<p>将wsl设置默认版本2</p>
<div class="jb51code"><pre class="brush:bash;">wsl --set-default-version 2</pre></div>
<p>将wsl1升级wsl2</p>
<blockquote><p>注意:wsl1不支持在ubuntu 64位系统编译运行32位程序,需先安装wsl2才行</p></blockquote>
<div class="jb51code"><pre class="brush:bash;">wsl --set-version Ubuntu 2</pre></div>
<p class="maodian"><a name="_label1"></a></p><h2>二、安装ubuntu</h2>
<p>WIN开始-&gt;microsoft store-&gt;搜索linux-&gt;Ubuntu安装</p>
<p style="text-align:center"><img alt="image" height="659" src="https://img.jbzj.com/file_images/article/202406/2024629154535939.png" width="800" /></p>
<blockquote><p>Ubuntu 22.04或者其他带版本只能使用当前版本的,后续无法升级,使用Ubuntu可以后续升级</p></blockquote>
<p>安装完成后</p>
<p><br /><img alt="image" height="766" src="https://img.jbzj.com/file_images/article/202406/2024629154535940.png" width="1468" /></p>
<p class="maodian"><a name="_label2"></a></p><h2>三、ubuntu简单配置</h2>
<p>1、首先更新镜像源</p>
<div class="jb51code"><pre class="brush:bash;">sudo apt update</pre></div>
<p>2、安装gcc g++</p>
<div class="jb51code"><pre class="brush:bash;">sudo apt install gcc g++</pre></div>
<p>3、安装git</p>
<div class="jb51code"><pre class="brush:bash;">sudo apt install git
/*
如果使用vim编辑,可以先在用户目录新建.vimrc
set number //可以显示行号

用户目录新建.gitconfig和.gitignore
-----------------------------------

      sslverify = false

      name = xxx
      email = xxx@xxx.com

      co = checkout
      br = branch
      ci = commit
      st = status
      sh = stash
      df = diff

      editor = vim
      excludesfile = /home/xxx/.gitignore
      symlinks = true
-----------------------------------
.nfs*

TODO.md
-----------------------------------
*/

</pre></div>
<p>4、安装ssh</p>
<div class="jb51code"><pre class="brush:bash;">sudo apt install openssh-server
ssh-keygen</pre></div>
<p>5、GCC 64位系统编译32位</p>
<div class="jb51code"><pre class="brush:bash;">sudo apt-get install build-essential module-assistant
sudo apt-get install gcc-multilib g++-multilib</pre></div>
<p>6、新建prj目录-&gt;hello目录-&gt;新建main.c</p>
<div class="jb51code"><pre class="brush:bash;">code . //可以使用改命令自动打开vscode</pre></div>
<p class="maodian"><a name="_label3"></a></p><h2>四、总结</h2>
<p></p>
<p>到此这篇关于Windows上安装WSL+Ubuntu来运行Linux环境的文章就介绍到这了,更多相关Windows上安装WSL+Ubuntu内容请搜索琼殿技术社区以前的文章或继续浏览下面的相关文章希望大家以后多多支持琼殿技术社区!</p>
頁: [1]
查看完整版本: Windows上安装WSL+Ubuntu来运行Linux环境