WSL2环境配置 您所在的位置:网站首页 wsl2配置haskell WSL2环境配置

WSL2环境配置

#WSL2环境配置| 来源: 网络整理| 查看: 265

WSL2环境配置 注意:功能需要hyper-v,与现下绝大多数的模拟器软件冲突 1. 程序和功能添加(需要重启)

控制面板-程序-启用或关闭windows功能,勾选“适用于Linux的Windows子系统“ 和 “虚拟机平台”

2. 配置WSL

设置WSL2为默认内核,更新WSL并重启WSL服务

wsl --set-default-version 2wsl --updatewsl --shutdown 3. 下载Ubuntu

在应用商城搜索Ubuntu并下载安装对应版本,之后打开即可。(在Windows terminal中,现在在+中也可以添加ubuntu终端了,界面非常漂亮)

按照提示输入用户名和密码(不需要和windows系统相同。密码输入不会回显)

4. (可选)映射网络驱动器

此电脑-映射网络驱动器,文件夹填\\wsl$\Ubuntu-20.04(-对应的版本号,可以先在文件资源管理器进入\\wsl$进行确认)

不要映射也挺好的,可以在文件资源管理器固定一个快速访问。

注意! 这个文件夹只有在ubuntu运行时才能打开。

5. Vscode配置wsl2终端

Vscode在插件市场搜索WSL(蓝底白字小企鹅图标)安装,之后侧边栏会出现“远程资源管理器”,点进去新建窗口即可。

可以先在Ubuntu建立一个工作文件夹、在Vscode中打开。

要运行代码,需要相应地配置Ubuntu代码环境和Vscode(远程)插件。

例如:C/C++

sudo apt install gccsudo apt install build-essential

如果中途出现Y/N选项,输入Y即可。

用gcc --version检查安装是否成功。

在Vscode中,也安装C/C++插件(这里的安装和本地vscode是不互通的!而是在工作区目录下新建.vscode文件夹)

现在,点击运行和调试均可正常运行了!

6. 其它 /mnt 是windows磁盘在wsl中的映射 7. linux代码环境配置 安装包的过程中出现# The following packages have unmet dependencies

解决办法

先执行

sudo apt-get updatesudo apt-get cleansudo apt-get autoremove

如果不行再执行

sudo apt --fix-broken install //修复系统中已安装的软件包依赖关系的错误,尝试下载并安装缺失的依赖软件包,并解决其他软件包冲突问题。sudo apt-get update && sudo apt-get upgrade //这会更新所有软件到最新版本,建议不要使用sudo dpkg --configure -a //重新配置未成功安装的软件包。sudo apt-get install -f //修复已安装的软件包依赖关系错误。当某些软件包在安装或卸载过程中出现问题时,可能会导致软件包依赖关系错误,此时可以执行该命令以修复依赖关系错误。需要注意的是,该命令并不会安装新的软件包,它只会修复已安装的软件包依赖关系错误。如果需要安装新的软件包,应该使用 sudo apt-get install 安装包的过程中出现Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/b/binutils/binutils-common_2.30-21ubuntu1~18.04.7_amd64.deb sudo vim /etc/apt/sources.list

全部替换

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

sudo apt-get update

许可协议

本文采用 署名-非商业性使用-相同方式共享 4.0 国际 许可协议,转载请注明出处。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有