Now that Windows (10) is getting closer and closer to Linux, it is very easy to use for developers, especially the Linux subsystem on Windows.
WSL2 (Windows Subsystem for Linux) is a tool on Windows 10 that allows developers to run the Linux environment directly on Windows, enabling a native Linux experience on Windows systems.
For WSL2, the bottom layer implements the Linux environment through Microsoft's built-in virtualization technology (Hyper-V). This article will walk you through how to enable WSL2 on Windows 10 and install an Ubuntu 20.04 distribution of Linux.
Preconditions
To enable WLS2 on Windows 10, the following conditions need to be met:
- Windows 10 version 1903 Build 19362, or later
- If it is an ARM64 system, you need version 2004 Build 19041, or higher
Step 1 - Enable Windows Services for WSL
To run WSL on Windows 10, you first need to enable some services on Windows, which are turned off by default.
Start menu, search for PowerShell
, right click PowerShell
, and select run as administrator.
In the opened PowerShell
terminal, execute the following command:
PS C:\Windows\system32> dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
[dism.exe] is a Windows deployment image service and management tool. The above command enables the WSL function.
After the above command is executed successfully, continue to execute the following command to enable Hyper-V function
PS C:\Windows\system32> dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
After completing the above operations, you need to restart the Windows operating system, and then log in to the system again after restarting.
Next, you need to download and install the latest Linux kernel upgrade package from Microsoft, download the installation package wsl_update_x64.msi , and install it directly after the download is complete.
After completion, run as administrator PowerShell
, execute the following command to set the default version used by wsl
PS C:\Windows\system32> wsl --set-default-version 2
Here we will default to wsl 2 .
The above steps have completed the enabling of WSL2, and the next step will be to use WSL2 to install a Linux-based distribution (Ubuntu 20.04).
Step 2 - Install Ubuntu 20.04 with WSL
After enabling the WSL function, installing a Linux distribution is very simple, just open the Windows Store (Microsoft Store), here we will install the Ubuntu 20.04 distribution.
After opening the app store, search for Linux directly in the app store, you will see many options for distribution versions, here select Ubuntu 20.04, click Get to add the application to the account, and then click the Install button to install it.
After the installation is complete, you can click Start to run the Ubuntu subsystem. The first run will take some time to initialize the configuration, and then you will be prompted to enter the user name and password of the Linux system.
The user name and secret here do not need to be the same as the user name and password of the Windows system, but administrative rights can be obtained through sudo
.
When the initialization is complete, the Linux subsystem can be used, of course, in the form of a terminal.
Step 3 - Install the Wdindows Terminal App (Windows Terminal)
The installed Ubuntu subsystem provides a default terminal, but Microsoft has open sourced a terminal tool on Windows - Windows Terminal, which supports many custom configurations, as well as Windows Powershell and Linux subsystem, so it can be installed and used .
Search Terminal directly in the app store, select Windows Terminal to install, and start it through the start menu after the installation is complete
Windows Terminal opens Powershell by default, but it supports multiple tabs. Click the drop-down button next to + Service on the title bar, select Ubuntu-20.04, and the new tab will open this subsystem terminal of Ubuntu.
Windows Terminal supports many custom configurations, please refer to its documentation for details.
Summarize
Now we have installed a full-featured Linux environment on Windows 10, which can be used to perform some Linxu system experiments and develop Linxu applications (it is more convenient to cooperate with the wsl plug-in of VSCode). In addition to the Ubuntu distribution, other supported distributions are available in the Microsoft App Store, including Debian, openSUSE, Kali, etc. You can also choose to install multiple environments.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。