Setup Ubuntu 20.04 using wsl on Windows 11

Durga Gadiraju
itversity
Published in
6 min readMar 26, 2022

Let us go through the details about setting up Ubuntu 20.04 using wsl on Windows 11 so that we can get power of Ubuntu 20.04 as part of your Windows 11 PC.

This article is part of Data Engineering on Cloud Medium Publication co-managed by ITVersity Inc (Training and Staffing) and Analytiqs Inc (Data Services Boutique)

Overview of Windows 11 Powershell

Windows Powershell is CLI on Windows which will provide following abilities.

  • Interact with Windows file system using commands.
  • Ability to install and use CLI based tools to manage services on Cloud Platforms such as AWS, Azure, etc.
  • Develop scripts to automate on Windows.
  • Ability to ssh to remote Linux or Unix based servers to support applications deployed on remote Linux or Unix based servers.

Even though Windows Powershell provide quite a few capabilities, it is not as robust as Ubuntu Terminal. Hence we would recommend to setup Linux on Windows using wsl.

Launching PowerShell

Here are the steps to launch powershell. You can go to search bar and launch Windows Powershell.

  • Open search bar and search for powershell.
  • Click on appropriate version of powershell to launch the powershell.

Overview of wsl

Let us get an overview of wsl before taking care of setting up Ubuntu 20.04 environment on Windows 11.

  • wsl stands for Windows Subsystem for Linux
  • In most of the Windows 11 PCs or Laptops, wsl comes out of the box.
  • wsl can be leveraged to setup Linux based virtual machines on Windows based PCs or Laptops.
  • You can launch powershell and run wsl -l command to see if there are any current running Virtual Machines.
  • If you do not have virtual machines yet, you can run wsl --install command. It will setup default Ubuntu based environment on your Windows PC.

Setup Ubuntu 20.04 on Windows 11

Let us go ahead and setup Ubuntu 20.04 on Windows 11.

  • You can list the available linux versions by running wsl -l --online . It will generate output like this.
  • We can install Ubuntu 20.04 based system using wsl --install -d Ubuntu-20.04. If this is the first system, you might have to reboot your Windows PC.
  • We can now start using Ubuntu 20.04. In future, you can go to Windows Powershell and run wsl -d Ubuntu-20.04 to get into the Ubuntu 20.04 system.

Managing Linux Systems using wsl

We can manage Linux Systems using wsl. We can get list of supported commands to manage Linux Subsystems by using wsl --help command.

  • List current subsystems — wsl -l
  • List subsystems with additional details such as version and state — wsl -l -v
  • Connect to specific subsystem — wsl -d Ubuntu-20.04. The subsystem will be started if it is in stopped state and then connects to specific subsystem.
  • Shutdown specific subsystem — wsl --shutdown -d Ubuntu-20.04.
  • Terminate specific subsystem — wsl --terminate -d Ubuntu-20.04. Both shutdown and terminate works in similar manner.

Setup Ubuntu 20.04 Desktop on Windows 11

For most of the scenarios just having Ubuntu 20.04 with command line is good enough. However, for some scenarios, it is better to have desktop setup. Let us understand how to setup Ubuntu 20.04 Desktop on Windows 11 which is setup using wsl. We will also understand how to access it using RDP.

  • Connect to Ubuntu 20.04 System running on Windows 11
  • Uninstall xrdp: We need xrdp up and running on the Ubuntu 20.04 system so that we can connect using rdp later from the host (Windows 11). However, we need to install xrdp after installing
sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get purge xrdp

It might prompt for the password. You are supposed to enter the password that is used while setting up Ubuntu 20.04 on Window 11 using wsl.

  • Install Ubuntu Desktop using xfce: There are multiple flavors of Ubuntu Desktop Display Managers such as lightdm, gdm3, etc. You will be asked to choose one of them while installing xfce. You can choose one of them as per your preference.
sudo apt-get install -y xfce4 xfce4-goodies

Mouse clicks will not work when prompted to choose display manager. You have to hit up and down arrows to choose between the options, then hit tab to go to <Ok>. Once Display Manager is chosen and when you are on <Ok>, make sure to hit enter. You also might have to hit space to get <Ok> selected.

  • Install xrdp
sudo apt-get install xrdp -y
  • Configure xrdp for xfce4: This will ensure that we can connect to Ubuntu Desktop via xfce4. We can use Windows RDP to connect to the Ubuntu Desktop later. Use nano or vi editor and make required changes to /etc/xrdp/startwm.sh. You can use sudo vi /etc/xrdp/startwm.sh to open using vi editor.

You need to comment out last 2 lines and add a new line as depicted in the image.

  • Take the back up of xrdp: If we make mistakes in updating settings in xrdp, we can leverage this back up file.
sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bkp
  • Update xrdp Settings: This will facilitate us to connect to Ubuntu Desktop via RDP from Windows 11 using specified port number.
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.inisudo sed -i 's/max_bpp=32/max_bpp=128/g' /etc/xrdp/xrdp.inisudo sed -i ‘s/#xserverbpp=24/xserverbpp=128/g’ /etc/xrdp/xrdp.iniecho xfce4-session > ~/.xsession
  • Start xrdp services: Only when xrdp services are running, we will be able to connect to Ubuntu Desktop from external hosts via RDP. We will also enable dbus as part of startup scripts so that it will automatically start on reboots.
sudo systemctl enable dbus
sudo /etc/init.d/dbus start
sudo /etc/init.d/xrdp start

Connecting to Ubuntu 20.04 Desktop

As we have setup Ubuntu 20.04 Desktop using wsl, now it is time for us to connect to the Desktop using Windows RDP.

  • Search for Remote Desktop and launch it.
  • Enter localhost:3390 as the hostname.
  • Make sure to enter right username and password used while setting up Ubuntu 20.04 using wsl.
  • Make sure to use xorg. We can save these credentials.

Advantages of using Ubuntu 20.04 on Windows 11

Here are some of the advantages of setting up and using Ubuntu 20.04 subsystem on Windows 11.

  • Fully functional linux terminal.
  • Ability to connect to remote servers via SSH.
  • Develop shell scripts using bash or ksh.
  • Ability to integrate premium version of IDEs such as IntelliJ, Pycharm, etc with wsl to get fully functional terminal as part of IDEs.
  • Ability to install CLIs to interact with Cloud Platforms.

--

--