在 Windows10 LTSC/Windows Server 2019 上安装 Windows Subsystem Linux(WSL)



  • Windows 10 LTSC和Windows Server 2019因为没有预装Windows Store,无法通过Windows Store安装WSL,必须采用手动安装。记录过程如下:

    1. 管理员权限运行powershell并运行下面的命令:
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
    
    1. 重启电脑(在powershell窗口键入Y即可)
    2. 下载Ubuntu 18.04安装包
    3. 修改文件后缀为zip,解压缩该文件。选个好位置,不能删了
    4. 用管理员身份运行ubuntu1804.exe
      如果不用管理员身份,有可能报错,例如:
    Installing, this may take a few minutes...
    WslRegisterDistribution failed with error: 0x80070005
    Error: 0x80070005 Access is denied.
    
    Press any key to continue...
    
    1. 耐心等待,需要几分钟时间,会请你输入用户名和密码
    Installing, this may take a few minutes...
    Please create a default UNIX user account. The username does not need to match your Windows username.
    For more information visit: https://aka.ms/wslusers
    Enter new UNIX username: 8508A
    Enter new UNIX password:
    Retype new UNIX password:
    passwd: password updated successfully
    Installation successful!
    To run a command as administrator (user "root"), use "sudo <command>".
    See "man sudo_root" for details.
    
    8508A@COMPUTERNAME:~$
    

    大功告成。

    想手动卸载可以用
    wslconfig /unregister Ubuntu



  • 执行WSL的过程中遇到提示:

    Installing, this may take a few minutes...
    WslRegisterDistribution failed with error: 0x800700b7
    The distribution installation has become corrupted.
    Please select Reset from App Settings or uninstall and reinstall the app.
    Error: 0x800700b7 Cannot create a file when that file already exists.
    

    搜了一下,不止我一个人遇到。
    github上说很多人重启LxssManager能解决问题

    sc query LxssManager
    sc stop LxssManager
    sc start LxssManager
    

    然而我没解决,执行

    dism /online /cleanup-image /restorehealth
    

    执行了很长时间,依然无效。
    灵机一动,让我重装APP是不是,我直接用powershell重装APPX
    还是从官方地址下载
    执行

    Add-AppxPackage -Path 下载文件名.appx
    

    居然成功安装上了,开始菜单出现了Ubuntu 18.04。
    用管理员执行,再走一次设置步骤就行了。



  • 换国内源并升级

    $ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    $ sudo sed -i 's/security.ubuntu/mirrors.aliyun/g' /etc/apt/sources.list
    $ sudo sed -i 's/archive.ubuntu/mirrors.aliyun/g' /etc/apt/sources.list
    $ sudo apt update && sudo apt-get upgrade -y