Environment: Windows 10 Enterprise 1809 (Detail Version:10.0.17763 Build 17763)
Windows Server 2019 (version 1709) and later
Steps:
1. 開始->Setting->輸入搜尋"Developer Setting", 或"development"
2. 選擇"Developer Mode"進行切換安裝
PS: 若安裝失敗(錯誤: 0x800d0954),檢查註冊表機碼: UseWUServer,修改成0,修改後"更新頁面"或"重新切換Mode"
(Path: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU)
3. 待Developer Mode(開發者模式)安裝切換完成後
使用PowerShell as Administrator and run: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
或使用Control Panel\Programs\Programs and Features->Turn Windows features on or off,選擇啟用"Windows Subsystem for Linux"
4. Download a Linux distribution,進入Ref 2下載所需要的版本
5. Using PowerShell to extract the <distro-version>.appx package's contents
例如:Administrator: PowerShell:
備註:如果是Server OS with Multi-user的環境,個別User需要自行安裝WSL,建議資料夾放在個別user底下的資料夾C:\Users\{USER}\{LinuxDistribution}{Version}_x64 E.g.: C:\Users\JR\Ubuntu2204_x64
PS C:\> cd C:\package-localtion\
PS C:\package-localtion\> Rename-Item .\Ubuntu_2004.2020.424.0_x64.appx .\Ubuntu.zip
PS C:\package-localtion\> Expand-Archive .\Ubuntu.zip .\Ubuntu
PS C:\package-localtion\> cd Ubuntu\
PS C:\package-localtion\> ubuntuxxxx.exe #(xxxx: 版本號碼)
PS C:\package-localtion\> .\ubuntu.exe config --default-user root #如果需要預設使用root登入的話
6. 等待安裝完成之後,設定username, userpassword,之後即可使用bash(WSL)
Ref 1: https://docs.microsoft.com/en-us/windows/wsl/install-on-server
Ref 2: https://docs.microsoft.com/en-us/windows/wsl/install-manual
====
筆記:
---
Install Methods 1:
https://learn.microsoft.com/zh-tw/windows/wsl/install-manual
WebGUI download https://aka.ms/wslubuntu2204 --> Get a Ubuntu2204-221101.AppxBundle
7-Zip open Ubuntu2204-221101.AppxBundle then click to open Ubuntu_2204.1.7.0_x64.appx
After open Ubuntu_2204.1.7.0_x64.appx, extract all file to user's folder: C:\Users\Gary\Ubuntu2204_x64
navigate to the folder, open powershell with administrator: .\ubuntu.exe
After installation, login with the user set when installing.
Switch to root user and set password.
Exit WSL
And set default user as root
.\ubuntu.exe config --default-user root
---
Install Methods 2:
Invoke-WebRequest -Uri https://aka.ms/wslubuntu2204 -OutFile Ubuntu2204.appx -UseBasicParsing
Add-AppxPackage Ubuntu2204.appx
---
Install Methods X:
Add-AppxPackage .\app_name.appx
---
simple-note:
--------------
cmd: ubuntu config --default-user username
PS >.\ubuntu.exe config --default-user root
--------------
使用 PowerShell 將 Linux 發行版本路徑新增至Windows環境 PATH (C:\Users\Administrator\Ubuntu :
$userenv = [System.Environment]::GetEnvironmentVariable("Path", "User")
[System.Environment]::SetEnvironmentVariable("PATH", $userenv + ";C:\Users\Administrator\Ubuntu", "User")
--------------
使用 PowerShell 將 Linux 發行版本路徑新增至Windows環境 PATH (C:\WSL\Ubuntu_2204.1.7.0 :
$userenv = [System.Environment]::GetEnvironmentVariable("Path", "User")
[System.Environment]::SetEnvironmentVariable("PATH", $userenv + ";C:\WSL\Ubuntu_2204.1.7.0", "User")
--------------
Server 2019: 使用 PowerShell 將 Linux 發行版本路徑新增至Windows環境 PATH (C:\Users\Gary\Ubuntu_x64 :
$userenv = [System.Environment]::GetEnvironmentVariable("Path", "User")
[System.Environment]::SetEnvironmentVariable("PATH", $userenv + ";C:\Users\Gary\Ubuntu_x64", "User")