Windows 10 上適用於 Linux 的 Windows 子系統安裝指南Windows Subsystem for Linux Installation Guide for Windows 10

安裝適用於 Linux 的 Windows 子系統Install the Windows Subsystem for Linux

您必須先啟用「Windows 子系統 Linux 版」選用功,才可以在 Windows 上安裝任何 Linux 發行版本。Before installing any Linux distributions on Windows, you must enable the "Windows Subsystem for Linux" optional feature.

以系統管理員身分開啟 PowerShell 並執行:Open PowerShell as Administrator and run:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

若只要安裝 WSL 1,您現在應該重新啟動電腦,並繼續安裝選擇的 Linux 發行版本,否則的話,請等候重新啟動完成,並繼續更新至 WSL 2。To only install WSL 1, you should now restart your machine and move on to Install your Linux distribution of choice, otherwise wait to restart and move on to update to WSL 2. 深入了解 WSL 2 和 WSL 1 的比較Read more about Comparing WSL 2 and WSL 1.

更新至 WSL 2Update to WSL 2

若要更新至 WSL 2,您必須符合下列準則:To update to WSL 2, you must meet the follow criteria:

啟用「虛擬機器平臺」選用元件Enable the 'Virtual Machine Platform' optional component

在安裝 WSL 2 之前,您必須啟用「虛擬機器平台」選用功能。Before installing WSL 2, you must enable the "Virtual Machine Platform" optional feature.

以系統管理員身分開啟 PowerShell 並執行:Open PowerShell as Administrator and run:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

重新啟動您的電腦,以完成 WSL 安裝並更新至 WSL 2。Restart your machine to complete the WSL install and update to WSL 2.

將 WSL 2 設定為預設版本Set WSL 2 as your default version

在 Powershell 中執行下列命令,以在安裝新的 Linux 發行版本時,將 WSL 2 設定為預設版本:Run the following command in Powershell to set WSL 2 as the default version when installing a new Linux distribution:

wsl --set-default-version 2

注意

從 WSL 1 更新至 WSL 2 可能需要幾分鐘的時間才能完成,視您的目標發行版本大小而定。The update from WSL 1 to WSL 2 may take several minutes to complete depending on the size of your targeted distribution.

安裝您選擇的 Linux 發行版本Install your Linux distribution of choice

  1. 開啟 Microsoft Store,然後選取您最愛的 Linux 發行版本。Open the Microsoft Store and select your favorite Linux distribution.

    Microsoft Store 中的 Linux 發行版本檢視

    下列連結會開啟每個散發套件的 Microsoft Store 頁面:The following links will open the Microsoft store page for each distribution:

  2. 從發行版本的頁面中,選取 [取得]。From the distribution's page, select "Get".

    Microsoft Store 中的 Linux 發行版本

設定新的發行版本Set up a new distribution

當您第一次啟動新安裝的 Linux 發行版本時,主控台視窗會隨即開啟,而系統會要求您等候一到兩分鐘,讓檔案解壓縮並儲存在您的電腦上。The first time you launch a newly installed Linux distribution, a console window will open and you'll be asked to wait for a minute or two for files to de-compress and be stored on your PC. 未來的所有啟動時間都應該會低於一秒。All future launches should take less than a second.

接著,您必須為新的 Linux 發行版本設定使用者帳戶和密碼You will then need to create a user account and password for your new Linux distribution.

Windows 主控台中的 Ubuntu 解壓縮

將發行版本設定為 WSL 1 或 WSL 2Set your distribution version to WSL 1 or WSL 2

若要針對每個已安裝的 Linux 發行版本檢查獲派的 WSL 版本,您可以開啟 PowerShell 命令列並輸入此命令 (僅適用於 Windows 組建 19041 或更高版本):wsl -l -vYou can check the WSL version assigned to each of the Linux distributions you have installed by opening the PowerShell command line and entering the command (only available in Windows Build 19041 or higher): wsl -l -v

wsl --list --verbose

若要設定要由任一版 WSL 所支援的發行版本,請執行:To set a distribution to be backed by either version of WSL please run:

wsl --set-version <distribution name> <versionNumber>

請務必將 <distribution name> 取代為發行版本的實際名稱,並使用數字 '1' 或 '2' 取代 <versionNumber>Make sure to replace <distribution name> with the actual name of your distribution and <versionNumber> with the number '1' or '2'. 您可以執行與上述相同的命令,隨時變更回 WSL 1,但將「2」取代為「1」。You can change back to WSL 1 at anytime by running the same command as above but replacing the '2' with a '1'.

此外,如果您要讓 WSL 2 成為您的預設架構,則可以使用以下命令來執行此動作:Additionally, if you want to make WSL 2 your default architecture you can do so with this command:

wsl --set-default-version 2

這會將已安裝的任何新發行版本設定為 WSL 2。This will set the version of any new distribution installed to WSL 2.

安裝疑難排解Troubleshooting installation

以下是相關錯誤和建議修正。Below are related errors and suggested fixes. 如需其他常見錯誤及其解決方案,請參閱 WSL 疑難排解頁面Refer to the WSL troubleshooting page for other common errors and their solutions.

  • 安裝失敗,發生錯誤 0x80070003Installation failed with error 0x80070003

    • 適用於 Linux 的 Windows 子系統只會在您的系統磁碟機上執行 (通常是您的 C: 磁碟機)。The Windows Subsystem for Linux only runs on your system drive (usually this is your C: drive). 請確定發行版本儲存在您的系統磁碟機上:Make sure that distributions are stored on your system drive:
    • 開啟 [設定] -> [儲存體] -> [其他儲存空間設定:變更新內容的儲存位置] 在 C: 磁碟機上安裝應用程式的系統設定圖片Open Settings -> Storage -> More Storage Settings: Change where new content is saved Picture of system settings to install apps on C: drive
  • WslRegisterDistribution 失敗,發生錯誤 0x8007019eWslRegisterDistribution failed with error 0x8007019e

    • 未啟用適用於 Linux 的 Windows 子系統選用元件:The Windows Subsystem for Linux optional component is not enabled:
    • 開啟 [控制台] -> [程式和功能] -> [開啟或關閉 Windows 功能] -> 勾選 [Windows 子系統 Linux 版] ,或使用本文開頭所述的 PowerShell Cmdlet。Open Control Panel -> Programs and Features -> Turn Windows Feature on or off -> Check Windows Subsystem for Linux or using the PowerShell cmdlet mentioned at the beginning of this article.
  • 安裝失敗,發生錯誤 0x80070003 或錯誤0x80370102Installation failed with error 0x80070003 or error 0x80370102

    • 請確定已在電腦的 BIOS 內啟用虛擬化。Please make sure that virtualization is enabled inside of your computer's BIOS. 有關如何執行此操作的指示會因電腦而異,並且很可能與 CPU 相關。The instructions on how to do this will vary from computer to computer, and will most likely be under CPU related options.
  • 嘗試升級時發生錯誤Invalid command line option: wsl --set-version Ubuntu 2Error when trying to upgrade: Invalid command line option: wsl --set-version Ubuntu 2

    • 請確定已啟用適用於 Linux 的 Windows 子系統,且使用的是 Windows 組建 19041 或更高版本。Please make sure that you have the Windows Subsystem for Linux enabled, and that you're using Windows Build version 19041 or higher. 若要啟用 WSL,請在具有系統管理員權限的 Powershell 提示中執行此命令:Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-LinuxTo enable WSL run this command in a Powershell prompt with admin privileges: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux. 您可以在這裡尋找完整的 WSL 安裝指示。You can find the full WSL install instructions here.
  • 由於虛擬磁碟系統限制,所以要求的作業無法完成。虛擬硬碟檔案必須是未壓縮和未加密的檔案,而且不得為疏鬆檔案。The requested operation could not be completed due to a virtual disk system limitation. Virtual hard disk files must be uncompressed and unencrypted and must not be sparse.

  • 無法辨識 'wsl' 詞彙是否為 Cmdlet、函式、指令檔或可執行程式的名稱。The term 'wsl' is not recognized as the name of a cmdlet, function, script file, or operable program.