Super detailed Windows10/Windows11 subsystem (WSL2) to install Ubuntu20.04 (with desktop environment)

foreword

Let me talk about why you want to install the desktop version of Ubuntu under the Windows subsystem. Some people may ask if the virtual machine is not good, is the dual system not good? Tossing the dual system will destroy the original environment if you don’t pay attention. If you install a virtual machine, the virtual machine may be very stuck due to computer hardware limitations and cannot be used normally, so this is only for those who don’t want to experience the above two kinds of pain. a way.

1. Install the Linux subsystem on Windows

prerequisite

  1. The windows machine needs to support virtualization, and virtualization technology needs to be enabled in the BIOS, because WSL2 is based on hyper-V.
    Check whether virtualization is enabled
    Press and hold Windows+Renter cmdto open the command line, enter

    systeminfo
    

    You can see the following words, which means that the computer already supports virtualization, and you can continue to install

    Hyper-V 要求:     虚拟机监视器模式扩展: 是
                      固件中已启用虚拟化: 是
                      二级地址转换: 是
                      数据执行保护可用: 是
    
  2. Whether it is Windows10 or Windows11, the Windows used is the latest version. If it is not the latest version, please update the system to the latest version in 设置- .Windows更新

installation steps

1. Enable developer mode

设置Search for "Developer Settings" in and open it; open
insert image description here
it 开发人员模式and click it , and the developer mode will be successfully turned on at this time.
insert image description here

2. Enable "Windows Subsystem for Linux"

Find 控制面板- 程序和功能- 启用或关闭Windows功能, select "Windows Subsystem for Linux", and click 确定insert image description hereto see that the computer responds as follows and is processing the changes.
insert image description here
insert image description here
insert image description here
Click on it 立即重新启动and wait for the computer to restart.

3. Install the Linux distribution

Microsoft official document

3.1 Upgrade the WSL kernel

Microsoft Official Documentation - Manual Installation Steps for Older Versions of WSL

Download the Linux kernel update package, which is suitable for WSL2 Linux kernel update package for x64 computers ;
double-click to run the update package just downloaded, with the suffix .msi, and the following installation interface will appear, click nextto install until the installation success interface appears.
insert image description here
insert image description here

3.2 Enable the virtual machine function

Before installing WSL 2, the "Virtual Machine Platform" optional feature must be enabled. A computer requires virtualization capabilities to use this feature. Open and run
as administrator :PowerShell

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

insert image description here
At this time, you need to restart the computer and wait for the computer to restart.

3.3 Set WSL 2 as the default version

Open it PowerShell, then run the following command to set WSL 2 as the default version when installing a new Linux distribution:

wsl --set-default-version 2

insert image description here

3.4 Install Ubuntu20.04

Open and 微软商店(Microsoft Store)search for "Ubuntu", then select and click Ubuntu20.04 LTSInstall until the download is complete;
insert image description here
at this time we can see the icon 开始of Ubuntu20.
insert image description here
Can.
insert image description here
After the password is entered, you can see the relevant information of Ubuntu20.04. So far, the installation of Ubuntu20.04 under the Windows subsystem is completed.
insert image description here
At this point, you can 此电脑see Linuxit in , open it to see Ubuntu files, and subsequent file operations with Ubuntu can be performed from here.
insert image description here

2. Install the desktop environment on the subsystem Ubuntu20.04

1. Replace the software source

Since Ubuntu's default software source is abroad, sometimes it may cause the download software to freeze. Here we replace it with the domestic Alibaba Cloud source, and other domestic sources are also available.

Double-click to open Ubuntu20.04 LTSthe icon, enter in the command line

# 备份原来的软件源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 编辑软件源
sudo nano /etc/apt/sources.list

Replace the original content with

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

as shown below, then press Ctrl + OSave, and press Ctrl + Xto exit edit mode.
insert image description here

2. Update and upgrade software

Execute the following commands in sequence on the Ubuntu command line:

# 更新软件源
sudo apt-get update -y
# 升级所有软件
sudo apt-get upgrade -y

3. Install the gnome desktop environment

The distribution version of Ubuntu installed under the Windows subsystem does not have a desktop environment by default. In order to be able to use the desktop environment, we need to install it manually. The desktop environment includes xfce4, gnome, etc. Here we choose the most classic gnome desktop environment, which is similar to the desktop environment of the official version of Ubuntu.

Execute the following commands in sequence on the Ubuntu command line:

# 安装gnome桌面环境
sudo apt-get install ubuntu-desktop
# 安装相关工具
sudo apt-get install gnome-tweak-tool

4. Install systemctl

The distribution version of Ubuntu installed under the Windows subsystem does not support the systemctl command by default. However, systemctl is very important in the native version of Ubuntu, and it is installed manually here.

Execute the following commands in sequence on the Ubuntu command line:

git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
bash ubuntu-wsl2-systemd-script.sh

注意: There may be a warning from the anti-virus software here. You need to allow all operations of the program or close the anti-virus software first. When you see the picture below, it means the installation is successful.
insert image description here
At this time, you need to restart the WSL service, open it in administrator mode PowerShell, and execute

# 停止服务
net stop LxssManager
# 启动服务
net start LxssManager

5. Install remote control software xrdp

Every time we double-click Ubuntu20.04 LTSthe icon to open it is a command line terminal, and we cannot see the desktop environment, so we need to install remote control software in Ubuntu, and then use mstscthe tools that come with Windows to achieve the purpose of visually operating Ubuntu.

Execute the installation command on the Ubuntu command line:

# 安装xrdp远程控制服务
sudo apt-get install xrdp

Change the port from 3389 to 3390, because the previous default 3389 port has been reserved for the ubuntu shell

sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini

Configure the session to start, otherwise the remote desktop login will crash directly after entering the password

echo "gnome-session" > ~/.xsession

Restart the xrdp service

sudo systemctl restart xrdp

At this time, you can view the status of the xrdp service

sudo systemctl status xrdp

As shown in the figure, a green running means the service runs successfully.
insert image description here

3. Boot Ubuntu Desktop from Windows

Press and hold Windows+ R, enter in the run box mstscand press Enter
insert image description here
计算机, and then localhost:3390press Enter to enter in English; here you can save this connection to the desktop in order to open it later.
insert image description here注::显示选项

Select
insert image description here
Enter your account and password here and click OK
insert image description here
There may be a short black screen after the previous step, don't be afraid! This is not because the configuration is not successful. After a short wait, you can see the picture below. So far, it means that the desktop environment has been successfully configured and can be entered normally!
insert image description here

You're done!

Guess you like

Origin blog.csdn.net/weixin_44301630/article/details/122390018