Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)

Time:2024-2-16

preamble

Here is why we should install the desktop version of Ubuntu under the Windows subsystem, some people may ask if the virtual machine does not smell good, dual-system does not smell good? Tossing dual system without noticing the original environment of the screwed up, the installation of virtual machines, then may be due to computer hardware limitations resulting in a virtual machine is very lagging can not be used properly, so here is only for the two pain do not want to go through the above another method.

I. Installing a Linux Subsystem on Windows

Prerequisite.

  1. The windows machine needs to support virtualization and needs to have virtualization turned on in the BIOS as WSL2 is hyper-V based.
    Check to see if virtualization is turned on
    hold downWindows+RimportationcmdOpen the command line and type

    systeminfo
    

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

    Hyper-V Requirements: VM Monitor Mode Extension: Yes
                      Virtualization enabled in firmware: Yes
                      Secondary Address Translation: Yes
                      Data Execution Protection Available: Yes
  2. Whether it is Windows 10 or Windows 11, the Windows used is the latest version, if it is not the latest version, theset upWindows UpdateUpdate the system to the latest version in the

Installation steps

1. Enable developer mode

inset upSearch for “Developer Settings” and open it;
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)
show (a ticket)Developer modeland clickisIf you want to use it, you have to turn on the developer mode successfully.
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)

2. Enable “Windows subsystems for Linux”.

locatecontrol panelPrograms and functionsEnabling or Disabling Windows FeaturesIf you want to change the “Windows Subsystems for Linux”, check “Windows Subsystems for Linux”, and then clickrecognizeWindows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)You can see the following response from the computer, which is processing the changes.
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)
At this point, clickImmediate restartJust wait for your computer to reboot and finish.

3. Installation of Linux distributions

Official Microsoft Documentation

3.1 Upgrading the WSL kernel

Microsoft Official Documentation – Manual Installation Procedures for Older WSL Versions

Download the Linux kernel update package.WSL2 Linux kernel update package for x64 computers
Double-click to run the update package you just downloaded with the suffix.msiIf the following installation screen appears, clicknextProceed with the installation until the Installation Success screen appears.
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)

3.2 Enabling the Virtual Machine Function

Before installing WSL 2, the Virtual Machine Platform optional feature must be enabled. The computer needs to be virtualized to use this feature.
Open as administratorPowerShellAnd run:

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

Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)
At this point, you need to restart your computer and wait for it to finish restarting.

3.3 Setting WSL 2 as the Default Version

show (a ticket)PowerShell, then run the following command when installing a new Linux distribution to set WSL 2 as the default version:

wsl --set-default-version 2

Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)

3.4 Installing Ubuntu 20.04

show (a ticket)Microsoft StoreSearch for “Ubuntu” and selectUbuntu20.04 LTSClick Install until the download is complete;
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)
At this point we can add thecommencementSee the Ubuntu 20.04 icon in the menu:
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)
Double-click to open can see the information of the registered account, according to personal habits enter the account name and password can be.
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)
After the password is entered, you can see the information about Ubuntu 20.04, and at this point the installation of Ubuntu 20.04 under the Windows subsystem is complete.
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)
At this point it is possible to set thethis computersee inLinuxIf you open it, you can see Ubuntu’s files, and subsequent file operations with Ubuntu can be performed from here.
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)

Second, install the desktop environment on the subsystem Ubuntu 20.04

1. Replacement of software sources

Because Ubuntu’s default software source in foreign countries, sometimes after the download software may cause lag, here we replace the domestic AliCloud source, other domestic sources can also be.

double-click to openUbuntu20.04 LTSicon, at the command line type

# Backup original software source
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# Editing software sources
sudo nano /etc/apt/sources.list

Replace the original 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, and then pressCtrl + OSave and pressCtrl + XExit edit mode.
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)

2. Updating and upgrading software

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

# Update software sources
sudo apt-get update -y
# Upgrade all software
sudo apt-get upgrade -y

3. Install the gnome desktop environment

The distributed version of Ubuntu installed under the Windows subsystem does not come with a desktop environment by default, in order to be able to use the desktop environment, we need to install it manually. There are desktop environments such as 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 from the Ubuntu command line:

# Install the gnome desktop environment
sudo apt-get install ubuntu-desktop
# Installation of related tools
sudo apt-get install gnome-tweak-tool

4. Install systemctl

Distributed Ubuntu installed under the Windows subsystem does not support the systemctl command by default, however systemctl is very important in native Ubuntu and is installed manually here.

Execute the following commands in sequence from 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

attention (heed): Here may be antivirus software will appear a warning, you need to allow all the operations of the program or first close the antivirus software, when you see the following picture shown on behalf of the installation is successful.
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)
At this point you need to restart the WSL service and open it in administrator modePowerShellImplementation

# Discontinued services
net stop LxssManager
# Start the service
net start LxssManager

5. Installation of remote control software xrdp

Every time we double-click on an openUbuntu20.04 LTSThe icons are all command line terminals and you can’t see the desktop environment, so you need to install remote control software in Ubuntu and then use Windows’ ownmstsctool for the purpose of visualizing and operating Ubuntu.

Execute the install install command from the Ubuntu command line:

# Install the xrdp remote control service
sudo apt-get install xrdp

Change the port from 3389 to 3390, as the default port 3389 was previously reserved for the ubuntu shell

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

Configure the startup session, otherwise the remote desktop login will flash directly after entering the password

echo "gnome-session" > ~/.xsession

Restart the xrdp service

sudo systemctl restart xrdp

At this point you can check the xrdp service status

sudo systemctl status xrdp

As shown, there are greenrunningRepresents successful operation of the service.
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)

III. Booting the desktop version of Ubuntu from Windows

hold downWindows+ RIn the run box, typemstscand then press enter
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)
calculatorimportationlocalhost:3390and then press enter
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)Notes:here are:for the English state; where it can be entered in theDisplay OptionsSave this connection to your desktop in the “Save to Desktop” section to make it easier to open it later.

optionis
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)
Enter your account and password here and click theOK
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)
After the previous step there may be a brief black screen, do not be afraid! This is not the configuration is not successful, wait a little while you can see the following picture, so that the desktop environment has been successfully configured and can be accessed normally!
Windows 10/Windows 11 Subsystem (WSL2) Installation of Ubuntu 20.04 (with desktop environment)

Great job!

Recommended Today

Java 8: Stream API Stream Operations

Java 8:Stream API The Stream API in Java 8 is a set of new features for working with collection data; providing a way to manipulate collections in a declarative style, simplifying the processing of collections, making the code cleaner, more elegant, and able to work with data more efficiently; This style treats the set of […]