Sometimes a Desktop GUI on top of your WSL2 comes handy. Let me describe shortly, what’s needed to run the XFCE Linux Desktop environment on top of your Ubuntu WSL.
To start, you need obviously your WSL2 setup and configured. This is a requirement I won’t cover here. Then, to get XFCE running, you need a so called X11 server running on your Windows host. This could be something like VcXsrv or MobaXTerm. In my case, I use MobaXTerm which brings a built in X11 server. Regardless of your X11 server, I recommend you to configure it to run X11 on a single window. For both named options, this is possible, using the settings. If you decide not to follow this advice, XFCE will open a new window for every application that’s started on your desktop, which will become messy really fast.
Now install xfce4
and xfce4-goodies
using the WSL shell.
sudo apt install xfce4 xfce4-goodies
To get you X11 connection forwarded to your X11 server, you need to specify the target display location in the DISPLAY environment variable. Therefore, you need to find out your WSL network adapters IP address. Open a Commandprompt or a Powershell terminal and enter the following:
ipconfig
...
Ethernet-Adapter vEthernet (WSL):
Verbindungsspezifisches DNS-Suffix:
Verbindungslokale IPv6-Adresse . : fe80::e827:47b7:e969:8d11%53
IPv4-Adresse . . . . . . . . . . : 172.27.0.1
Subnetzmaske . . . . . . . . . . : 255.255.240.0
Standardgateway . . . . . . . . . :
...
Note down the IPv4 address and proceed into your WSL shell. The next step depends on your shell you’re using in the terminal. If you haven’t changed anything, this will be bash. Edit the .bashrc
in your users home then and add the following line:
export DISPLAY=172.27.0.1:0.0
Enter the IP address noted from above and save the file. Now reopen the terminal or source the .bashrc
by:
source ~/.bashrc
The only thing that’s missing is to start XFCE by the startxfce4
command. You will get a lot or warning and error messages which can be ignored mostly. After some seconds of waiting, the XFCE desktop environment should show up in your X11 Server window.
Philip