WSL Ubuntu 18.04 LTS + VS Code

时间:2023-09-18 09:39:26

WSL Ubuntu 18.04 LTS + VS Code

​ WSL(Windows Subsystem for Linux)使得Windows用户能够在Windows系统上使用原生的Linux环境,为Windows环境下使用Linux环境提供了新的解决方案。

WSL

Install

  1. Windows环境设置

    • 控制面板 -> 程序 -> 程序和功能 -> 启用或关闭Windows功能 -> 选择"适用于Linux的Windows子系统"
    • Powershell运行 Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

    两种方法均可

  2. WSL Ubuntu安装

    Windows Store搜索"Ubuntu",选择相应版本即可

  3. Ubuntu配置

  • 清华源:https://mirrors.tuna.tsinghua.edu.cn/ubuntu

    [清华源使用帮助](https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/)
    # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse # 预发布软件源,不建议启用
    # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

    复制以上内容至剪贴板,以上使用阿里云源,清华源更换URL即可。接下来在Bash界面打开sources.list文件修改软件源。

    cd /etc/apt/

    sudo cp ./sources.list ./sources.list.backup

    sudo vim ./sources.list

    // 将内容置换

    // 查找可更新的软件

    sudo apt-get update

    // 执行更新

    sudo apt-get upgrade

Uninstall

  1. Powershell执行wslconfig /l查看已安装的WSL列表
  2. wslconfig /u Ubuntu-18.04

VS Code

Install

  • 安装时勾选"将环境变量添加到Path"

  • 安装"Remote Development"插件

WSL+VS Code

Open a remote folder or workspace

Microsoft 参考文档

Debugging in WSL with Python