1、打开功能支持 WSL以管理员权限打开 PowerShell 终端,执行以下指令Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux开启 Linux 子系统支持的功能。也可以在图形界面下,点击“添加服务器功能” 中勾选相应功能。
2、初次开启此功能,会涉及到重启操作系统。PS> Enable-WindowsOptionalFe锾攒揉敫ature -Online -FeatureName Microsoft-Windows-Subsystem-Linux Path : Online : True RestartNeeded : False命令执行的话,显示上述信息,就表示功能已打开,无需重启。下载 Linux 分发包文件到微软云的下载页面https://docs.microsoft.com/en-us/windows/wsl/install-manual下载需要的 Linux 发行版这里示例使用 ps 脚本下载远程文件,以 Ubuntu 18.04 版本为例Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile ~/Ubuntu1804.appx -UseBasicParsing或者使用 curl.exe 方式进行下载:curl.exe -L -o ~/ubuntu1804.appx https://aka.ms/wsl-ubuntu-1804开始解包文件使用如下命令,进行操作:Rename-Item ~/Ubuntu1804.appx ~/Ubuntu1804.zip Expand-Archive ~/Ubuntu1804.zip ~/Ubuntu1804
3、解压文件后,可以看到如图的文件目录内容。
4、开始安装 Linux 子系统打开 ubuntu1804.exe 即可开始进入命令行安装界面:Installing, this may take a few mi荏鱿胫协nutes... 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: YourUserName 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. eric@WIN-SERVER2019:~$稍等片刻,即可开始输入自定义用户名,输入密码,安全完成。