手動下載 Windows 子系統 Linux 版散發版本套件Manually download Windows Subsystem for Linux distro packages

在幾種情況下,您可能無法 (或想要) 透過 Microsoft Store 安裝 WSL Linux 散發版本。There are several scenarios in which you may not be able (or want) to, install WSL Linux distros via the Microsoft Store. 具體而言,您可能正在執行不支援 Microsoft Store 的 Windows Server 或長期維護 (LTSC) 桌面作業系統 SKU,或公司網路原則及/或系統管理員不允許在您的環境中使用 Microsoft Store。Specifically, you may be running a Windows Server or Long-Term Servicing (LTSC) desktop OS SKU that doesn't support Microsoft Store, or your corporate network policies and/or admins to not permit Microsoft Store usage in your environment.

在這些情況下,雖然 WSL 本身可供使用,但是如果您無法存取商店,如何在 WSL 中下載並安裝 Linux 散發版本?In these cases, while WSL itself is available, how do you download and install Linux distros in WSL if you can't access the store?

注意:不允許在 Windows 10 S 模式上執行命令列命令介面環境,包括 Cmd、PowerShell 和 Linux/WSL 散發版本。Note: Command-line shell environments including Cmd, PowerShell, and Linux/WSL distros are not permitted to run on Windows 10 S Mode. 這項限制是為了確保 S 模式所提供的完整性和安全目標:如需詳細資訊,請參閱這篇文章 (英文)。This restriction exists in order to ensure the integrity and safety goals that S Mode delivers: Read this post for more information.

正在下載散發版本Downloading distros

如果無法使用 Microsoft Store 應用程式,您可以按一下下列連結,下載並手動安裝 Linux 散發版本:If the Microsoft Store app is not available, you can download and manually install Linux distros by clicking these links:

這會導致將 <distro>.appx 套件下載到您選擇的資料夾。This will cause the <distro>.appx packages to download to a folder of your choosing. 依照安裝指示安裝下載的散發版本。Follow the installation instructions to install your downloaded distro(s).

透過命令列下載散發版本Downloading distros via the command line

如果您想要的話,也可以透過命令列下載您偏好的散發版本:If you prefer, you can also download your preferred distro(s) via the command line:

使用 PowerShell 下載Download using PowerShell

若要使用 PowerShell 下載散發版本,請使用 Invoke-WebRequest Cmdlet。To download distros using PowerShell, use the Invoke-WebRequest cmdlet. 以下是下載 Ubuntu 16.04 的範例指示。Here's a sample instruction to download Ubuntu 16.04.

Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu.appx -UseBasicParsing

提示

如果下載花費較長的時間,請設定 $ProgressPreference = 'SilentlyContinue' 來關閉進度列If the download is taking a long time, turn off the progress bar by setting $ProgressPreference = 'SilentlyContinue'

使用 curl 下載Download using curl

Windows 10 春季 2018 更新 (或更新版本) 包含熱門的 curl 命令列公用程式,您可以從命令列叫用 Web 要求 (例如 HTTP GET、POST、PUT 等命令)。Windows 10 Spring 2018 Update (or later) includes the popular curl command-line utility with which you can invoke web requests (i.e. HTTP GET, POST, PUT, etc. commands) from the command line. 您可以使用 curl.exe 下載上述散發版本:You can use curl.exe to download the above distros:

curl.exe -L -o ubuntu-1604.appx https://aka.ms/wsl-ubuntu-1604

在上述範例中,會執行 curl.exe (而不只是 curl),以確保在 PowerShell 中叫用實際 curl 可執行檔,而不是 Invoke-WebRequest 的 PowerShell curl 別名In the above example, curl.exe is executed (not just curl) to ensure that, in PowerShell, the real curl executable is invoked, not the PowerShell curl alias for Invoke-WebRequest

注意:如果您必須使用 Cmd 命令介面及/或 .bat / .cmd 指令碼來叫用/編寫下載步驟,則最好使用 curlNote: Using curl might be preferable if you have to invoke/script download steps using Cmd shell and/or .bat / .cmd scripts.

安裝散發版本Installing your distro

如果您使用的是 Windows 10,您可以使用 PowerShell 安裝散發版本。If you're using Windows 10 you can install your distro with PowerShell. 只要瀏覽至包含從上述位置所下載散發版本的資料夾,然後在該目錄中執行下列命令,其中 app_name 是散發版本 .appx 檔案的名稱。Simply navigate to folder containing the distro downloaded from above, and in that directory run the following command where app_name is the name of your distro .appx file.

Add-AppxPackage .\app_name.appx

如果您使用的是 Windows Server,可以在 Windows Server 文件頁面上找到安裝指示。If you are using Windows server you can find the install instructions on the Windows Server documentation page.

安裝發行版本之後,請遵循正常指示 更新至 WSL 2建立新的使用者帳戶和密碼Once your distribution is installed, follow the normal instructions to update to WSL 2 or create a new user account and password.