Win 10 以來,微軟操做系統內置支持 Linux 子系統,win 10 上面自帶有 Microsoft Store 應用商店,能夠直接安裝 Linux 子系統,可是在 Server 2016 / 2019 上,系統並無內置 Microsoft Store 應用商店,因此不能經過商店直接安裝子系統。ubuntu
下面就來介紹一下,Server 2016/2019 服務器操做系統上怎樣安裝 Linux 子系統。windows
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
開啓 Linux 子系統支持的功能。安全
也能夠在圖形界面下,點擊「添加服務器功能」 中勾選相應功能。服務器
PS> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux Path : Online : True RestartNeeded : False
命令執行的話,顯示上述信息,就表示功能已打開,無需重啓。app
到微軟雲的下載頁面 https://docs.microsoft.com/en-us/windows/wsl/install-manual 下載須要的 Linux 發行版curl
這裏示例使用 ps 腳本下載遠程文件,以 Ubuntu 18.04 版本爲例ide
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile ~/Ubuntu1804.appx -UseBasicParsing
或者使用 curl.exe 方式進行下載:this
curl.exe -L -o ~/ubuntu1804.appx https://aka.ms/wsl-ubuntu-1804
使用以下命令,進行操做:url
Rename-Item ~/Ubuntu1804.appx ~/Ubuntu1804.zip Expand-Archive ~/Ubuntu1804.zip ~/Ubuntu1804
解壓文件後,能夠看到如圖的文件目錄內容。操作系統
打開 ubuntu1804.exe 便可開始進入命令行安裝界面:
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: 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:~$
稍等片刻,便可開始輸入自定義用戶名,輸入密碼,安全完成。