Joseph Gan
Joseph Gan's Blog

Joseph Gan's Blog

Enhance your WSL 2 experience with Xfce4

Enhance your WSL 2 experience with Xfce4

Joseph Gan's photo
Joseph Gan
·Feb 5, 2022·

6 min read

Table of contents

  • Introduction
  • What is WSL 2?
  • Installation
  • Installing Xfce4
  • Alternative to Xfce4?
  • Conclusion

Introduction

In this article, I want to talk about enhancing your WSL 2 experience by installing Xfce4 as the Desktop Environment where you can remote into using Windows Remote Desktop Connection

This is especially useful if you are still not quite used to using just command-line or you prefer using GUI to navigate around the OS

What is WSL 2?

Quote directly from microsoft

WSL 2 uses the latest and greatest in virtualization technology to run a Linux kernel inside of a lightweight utility virtual machine (VM). However, WSL 2 is not a traditional VM experience

In my opinion, it improves the developer experience without the need to dual boot or runs a separate Linux VM to experience the native Linux user experience, and improve the quality of a developer life

Installation

Minimally, you need to be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11

  • Launch your terminal
  • Run wsl --install
    • Ubuntu is the default distribution
    • You are free to choose any other distribution to your liking
    • It should take a little while to install
  • Once installed, it will prompt you to setup your username and password
  • Once done, it will be ready to use

If you are curious, the installed path would be at %UserProfile%\AppData\Local\Packages\

For Ubuntu, the actual path would be %UserProfile%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc but for other distribution such as Kali-Linux, it would be %UserProfile%\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg

Ensure distribution running on WSL 2

If you have installed via wsl --install command, by default, it should already be using version 2

After the installation is completed, let's confirm that we are using version 2 and not version 1

  • Launch your terminal
  • Run wsl -l -v
    • -l refers to list for listing all existing distributions
    • -v refers to verbose where it displays detailed information regarding the distribution such as the version

Run wsl -help to view all command options

wsl-2-l-v.gif

❯ wsl -l -v
NAME                   STATE           VERSION
* Ubuntu                 Running         2
  • This shows us that we are running on Ubuntu distribution and am indeed on version 2
  • If you are on version 1, then you should convert to version 2 by running wsl --set-version Ubuntu 2
    • This will start the process to convert from version 1 to version 2
    • It will take a short while to perform the conversion

WSL default version can be set to version 2 by running wsl --set-default-version 2

Based on my understanding, the difference between version 1 and version 2 in terms of installation is that for version 1, it would have stored all the files in %installed_directory%\rootfs whereas for version 2, it stores all the files in %installed_directory%\ext4.vhdx which is a virtual drive

Set default distribution

Distribution

There are a few distributions for us to install if you do not want to use Ubuntu

  • Run wsl -l -o to view the available distribution
    • -l refers to list for listing all existing distributions
    • -o refers to online where it displays list of available distributions for install

wsl-2-l-o.gif

❯ wsl -l -o
The following is a list of valid distributions that can be installed.
Install using 'wsl --install -d <Distro>'.

NAME            FRIENDLY NAME
Ubuntu          Ubuntu
Debian          Debian GNU/Linux
kali-linux      Kali Linux Rolling
openSUSE-42     openSUSE Leap 42
SLES-12         SUSE Linux Enterprise Server v12
Ubuntu-16.04    Ubuntu 16.04 LTS
Ubuntu-18.04    Ubuntu 18.04 LTS
Ubuntu-20.04    Ubuntu 20.04 LTS

If you have a number of installed distributions installed on your machine, you can set the default distribution by running wsl --setdefault <distribution>

> wsl --setdefault Ubuntu
  • this is so that when we type wsl, it will know to launch the correct distribution
  • the * beside the distribution name indicates the default distribution

Oracle Linux 8.5 has recently landed as one of the newer distributions as well

Installing Xfce4

Now that you have set up and installed your favorite Linux distribution on your machine, where you can access it via the terminal. What's next? You can improve then your experience by navigating the OS using GUI (Desktop Environment)

Xfce is a lightweight desktop environment for UNIX-like operating systems. It aims to be fast and low on system resources, while still being visually appealing and user friendly

The installation will take up around 2-3gb of disk space and some time to finish, please be patient

  • Launch your terminal
  • Run wsl
    • This will get you into the Ubuntu shell
    • Input user credential as prompted (if required)
  • Run the following commands one by one

wsl-xfce4.gif

I skipped a portion of the gif to remove the waiting time (total duration is 1:29 seconds)

> wsl

sudo apt update -y && sudo apt upgrade -y
sudo apt install xfce4 -y [1]
sudo apt install xrdp -y [2]
echo xfce4-session > ~/.xsession [3]
sudo service xrdp restart
sudo apt install net-tools -y [4]
ifconfig | grep inet
  1. Choose gdm3 when prompted during the installation
  2. xrdp allows us to RDP into the distro from Windows RDP
  3. Without this, you might get disconnected immediately after connecting via RDP
  4. Running ifconfig | grep inet will display the ip address to remote in
inet 172.23.201.70 netmask 255.255.240.0  broadcast 172.23.207.255
inet6 fe80::215:5dff:fe74:4236  prefixlen 64  scopeid 0x20<link>
inet 127.0.0.1  netmask 255.0.0.0
inet6 ::1  prefixlen 128  scopeid 0x10<host>

Take note of the inet address

Access using Windows RDP

Once installed, it is now to try to access via Windows Remote Desktop Connection

  • Launch Search bar
  • Type remote desktop connection
  • Input the ip and click connect

windows-rdp.png

  • Once connected, proceed to input your credentials

linux-xrdp.png

  • And you have a fully functional Desktop Environment

ubuntu-desktop.png

  • You will be able to browse to your host OS using the explorer as usual

Alternative to Xfce4?

XUbuntu

The instruction to install XUbuntu would mostly be the same as installing Xfce4 except to run this for the first command. XUbuntu also comes with Xfce but provide a richer experience compared to Xfce

sudo apt install xubuntu-desktop -y
// the rest of the commands will be the same as installing Xfce4

Note that xubuntu takes up around 5-6gb of disk space

GWSL

Well, it's not exactly an alternative per se because of how it works. But end state is that you will be interacting in a graphical mode rather than command line

So if you would rather run the apps on your Windows OS instead of remote into the Linux distribution, then you can try GWSL. It lets you run graphical Linux apps on Windows 10 directly. It certainly looks pretty damn good to me but I haven't tried it myself. If you do try it, let me know your experience in the comments

I embedded a youtube demo taken from their website

Conclusion

WSL has come a long way from having to download Linux kernel, enable WSL and Virtual Machine Platform feature, set WSL 2 as default version and so on down to just a single command - wsl --install

Furthermore, we are still able to navigate and experience the OS through Xfce4 instead of just on the terminal which is sometimes the preferred way for some users (especially for Windows users)

Hope you find this article useful

 
Share this