Important Note:
📌The operating system demonstrated in this document is Windows 10 Pro. Please be aware of this.
To install WSL 2 on Windows 10, you will need the following:
- Windows 10 (x64) Version 1903 or higher, Build 18362.1049 or above.
- A computer that supports Hyper-V virtualization.
1. Install PowerShell and Windows Terminal
Simply download and install these tools from the Microsoft Store.
Download PowerShell
:
https://apps.microsoft.com/detail/9MZ1SNWT0N5D?rtc=1&hl=zh-cn&gl=CN
Download Windows Terminal
:
https://www.microsoft.com/store/productId/9N0DX20HK701?ocid=pdpshare
We will be using these tools frequently in the following steps.
2. Enable Windows Subsystem for Linux (WSL)
After installing PowerShell, proceed as shown in the image below.
WARNING
📌 Be sure to run PowerShell as an administrator!
hen, enter the following command in the terminal:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
3. Enable Virtual Machine Platform
There are two methods to enable this:
- Using PowerShell Command Line
- Using the Graphical Interface Settings Choose one of these methods. If one doesn’t work, try the other.
1. PowerShell Command Line Method
In the PowerShell command line, enter the following command:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
2. Graphical Interface Settings Method
In the search box, type 【Turn Windows features on or off】
Find the option in the GIF image below in the window and check the checkbox.
3. Restart Your Computer
Regardless of which method you used to enable Virtual Machine Platform, you will need to restart your computer for the changes to take effect.
4. Download and Install the Linux Kernel Update Package
The Linux kernel update package installs the latest version of the WSL 2 Linux kernel, enabling WSL to run in the Windows environment.
There are two ways to download it:
- Direct Download from This Guide: No need to visit the Microsoft website.
- Direct Download from the Microsoft Website
1. Direct Download from Here
Download the file below, extract it, and double-click to start the installation. Simply follow the prompts, clicking “Next” until completion.
Download【wsl_update_x64.zip】
📌 Download Center (Click to Go)
📌 In Download Center
->Baidu Netdisk Resource Content
->Chapter 07. Development Tools
->wsl_update_x64.zip
Once you see the following screen, click Finish to complete the installation.
2. Official Download
Notice
📌 Official Download Link: https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
Click on the link above to download. After the download completes, double-click to run the installer, clicking “Next” until finished. Once you see the screen below, click Finish.
5. Set WSL 2 as the Default Version
Open PowerShell and enter the following command to set WSL 2 as the default version:
wsl --set-default-version 2
6. Install Ubuntu
There are two methods to install Ubuntu:
- Via Microsoft Store (easier)
- Via PowerShell (more advanced)
1. Installing Ubuntu through Microsoft Store (Easy Method)
WARNING
📌 Note: Installing Ubuntu from the Microsoft Store defaults to the C: drive. If your C: drive lacks space, proceed with caution!
Microsoft App Store is kind of better, we download Ubuntu 20.04 directly from the store.
To download Ubuntu 20.04, start by clicking the Windows Start icon.
This will open the Microsoft Store (note that it may take a moment to load).
In the search bar at the top, type 【Ubuntu20.04】 and press Enter
Select 【Ubuntu 20.04.6 LTS】 version to download.Note that I downloaded it here so I don't need to download it again.
Once installed, you can verify it by running the following in PowerShell:
wsl --list --verbose
If installed successfully, you’ll see Ubuntu listed:
2. Installing Ubuntu via PowerShell Commands (Advanced Method)
We download a distribution of Ubuntu via the link below.
- First, visit the following link: https://store.rg-adguard.net/
- In the search box, enter the link below and click the search button.
https://apps.microsoft.com/detail/9MTTCL66CPXJ?ocid=pdpshare&hl=en-us&gl=US
- Choose a download location you prefer.
For example, F:\WSL2_Ubuntu20.04
- Rename the downloaded file’s extension to .zip.
- Original filename:
CanonicalGroupLimited.Ubuntu20.04LTS2004.6.16.0_neutral~_79rhkp1fndgsc.AppxBundle
- Renamed to:
CanonicalGroupLimited.Ubuntu20.04LTS2004.6.16.0_neutral~_79rhkp1fndgsc.zip
- Extract the files to the current folder.
- Locate the file Ubuntu_2004.6.16.0_x64.appx and rename it to Ubuntu_2004.6.16.0_x64.zip
(delete any unneeded files).
- Extract the compressed file Ubuntu_2004.6.16.0_x64.zip, and you should get the following folder:
- Open this folder, right-click, and run Ubuntu2004.exe as an administrator:
- Wait while the installation completes:
- Enter your username and password (Note: Do not set your username as 'root' because this user already exists by default):
- And that's it—you’re all set!
7. Setting the Default Linux Version to Run
Open PowerShell and enter the following command:
wsl --set-default Ubuntu-20.04
8. Enabling Developer Mode
Some computers may not have this option. You can skip this step if that’s the case. Enabling this setting can prevent certain errors on some devices.
- Toggle Developer Mode on:
9. Setting Read/Write Permissions
Directly accessing and writing to the WSL2 directory from Windows can sometimes cause permission issues. As you will need to place SDK files within the WSL2 directory for SDK compilation, ensure that you have permission to access this directory.
Open PowerShell and enter the following command (assuming the default user is set to root):
F:\WSL2_Ubuntu20.04\Ubuntu_2004.6.16.0_x64\ubuntu2004.exe config --default-user root
Note: The path F:\WSL2_Ubuntu20.04\Ubuntu_2004.6.16.0_x64\ubuntu2004.exe reflects my personal directory. Adjust accordingly if your path is different.
10. Restart Your Computer
After restarting, the parameters we set will take effect.
11. Running Ubuntu
1. For Installations from the Microsoft Store
If you downloaded Ubuntu from the Microsoft Store, follow these steps to open it:
- Click the Bookshelf icon, then select Terminal and open it.
- Once the window opens, click the dropdown menu, and select 【Ubuntu 20.04.6 LTS】 to open it.
- Wait for a moment. On the first launch of WSL Ubuntu, you'll be prompted to set up a username and password.
Note: You cannot set root as your username since it already exists by default. Choose a different username and follow the prompts to set a password.
2. For Installations Using PowerShell Commands
Locate the directory where you placed the installation package, find the .exe file, and double-click to run it.
12. Transferring Files from Windows to Ubuntu
This process is commonly used for transferring SDKs to Ubuntu for compilation. In the Ubuntu command line, enter the following command to view all files in Windows:
sudo ls /mnt/*
You can locate the path and then use the cp command to copy files to Ubuntu (if copying a folder, compress it first).
- /mnt/d/hello.c refers to a file named hello.c on the D drive in Windows.
- /home/lckfb/world.c refers to the file world.c in the home/lckfb directory in Ubuntu.