This article was published originally on derkoe.dev.
This guide shows how to setup a full development environment including UI apps (X11) in WSL2 on Windows 10. WSL2 enables a "full" Linux development environment in Windows.
Why?
The first thing you might ask is: why? First, we have to run Windows on our machines - so the all-in Linux does not work. Second, Linux is a lot faster for building software than Windows - our biggest app compiles in 13 minutes under Windows and in just 2 minutes under WSL on my machine which is a massive improvement.
Enable WSL2 and Install Ubuntu
For WSL2 to work you will need a Windows 10 build 19041 (aka 20H1) or higher (any edition will work, even Home). Then simply follow the guide from Microsoft.
TL;DR:
- Enable the features WSL and VM-Platform in Powershell as Admin:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
- Restart Windows
- Set WSL2 as default:
wsl --set-default-version 2
- Go to the Microsoft Store and install "Ubuntu"
- Launch Ubuntu from Start menu (this will ask you for a user account)
You can now re-launch a shell in your Ubuntu instance with "Ubuntu" from the Start menu or execute wsl
from the command line. The WSL command line tool has many options which you can find with wsl --help
or in the Command Reference.
Update and Install Software
Inside your Ubuntu Linux update all packages:
sudo apt update
sudo apt upgrade
Then install packages you need for your development - in my case it is Java 11, Maven, Node.js/NPM and git:
sudo apt install openjdk-11-jdk openjdk-11-source maven nodejs npm git
Do not install Docker CLI or Docker Compose because these are provided by Docker Desktop (see next section).
Install Docker (optional)
Most developers need Docker for their local setup - the newest Docker Desktop version supports WSL2 out of the box (even on Windows Home).
GUI Apps
Currently there is no support for GUI apps for WSL - Microsoft has announced that they are working on GUI support using Wayland and that it should ship in 2020. So you have to use X11 forwarding or other tricks to enable this - I have tried all of them and there are some issues with any of the solutions:
- X11 server on Windows (VcXsrv or X410) and setting the DISPLAY variable in Linux (
export DISPLAY=
ip route show | grep 'default via' | awk '{print $3}'
:0.0
in your.bashrc
).- Works quite well - good performance, shortcuts work, even mouse back/forward buttons work as expected
- The main problem is that when you go to standby or hibernate the connection between Windows and WSL breaks and all your apps stop. If you can live with that go with this solution!
- Running xrdp on Linux and using Remote Desktop to connect
- In this case you are running a full desktop - that means you have to install Xfce (Gnome does not seem to work).
- With this solution the whole UI feels a bit laggy and slow - I tried to tune the xrdp params without success.
-
Xpra - a virtual X11 server to connect via a client on Windows (or other platforms)
- The solution works but there are many issues like crashes, window positions are completely wrong, extra mouse buttons do not work, etc.
-
X2Go - also a virtual X11 server with an Windows client
- This seems to be the most promising solution
- As with plain X11: good performance, shortcuts work, even mouse back/forward buttons work as expected, plus the reconnect feature
- The only drawback is the quirky Windows client (but I got used to it)
X2Go
Here is the X2Go setup in more details (since it worked best for me).
Initial setup
- Fix SSH host keys
sudo apt-get remove --purge openssh-server
sudo apt-get install openssh-server
sudo service ssh --full-restart
- Install X2Go on your Linux distribution
apt install x2goserver
Download and install the client for Windows.
-
Configure the
- Host:
localhost
- Login:
<your user>
- Session type: Published Applications
- Host:
After each WSL/Windows restart
- Launch ssh in Linux (if not started yet):
sudo service ssh start
- Launch "X2Go Client" on Windows ad connect to the server with user/password
- Now you can launch X11 apps via the tray icon (see X2Go Published Applications)
Editors/IDEs
Visual Studio Code
Simply install VSCode and then you can open it from the Linux shell with code
or code <path>
- most of the time it will be:
code .
IntelliJ IDEA
On a normal Ubuntu you could install IntelliJ IDEA via Snap but Snap does not work on WSL2 (there is a hacky workaround).
So, the easiest way is to install it manually:
- Get the latest tar.gz from the downloads page
- Extract it an create a symlink (so you can easily switch versions):
cd /opt
sudo tar xzf /mnt/c/Users/$USER/Downloads/idea-{edition-version}.tar.gz
sudo ln -s /opt/idea-{edition-version} /opt/idea
- To easily launch the app via the X2Go context menu create an app desktop entry
/usr/share/applications/intellij-idea.desktop
with the following contents:
[Desktop Entry]
Name=Intellij IDEA
Comment=JetBrains Intellij IDEA Java IDE
Categories=Development
Keywords=java;ide
Exec=/opt/idea/bin/idea.sh
Type=Application
Icon=/opt/idea/bin/idea.png
Open Issues
There are still many issues with WSL2 - the biggest problems are:
Systemd is not running - the official issue is Blockers for systemd?. Seems like Microsoft is working with the Systemd team on this problem. Anyway withoud Systemd you cannot run any services and things like Snap packages do not work. There are some workarounds like genie or this instructions.
GUI apps are a pain (in the a..) - like alrady mentioned above.
There are many troubles with VPN solutions: CISCO AnyConnect, Checkpoint VPN.
Top comments (2)
I followed your instructions for x2go but somehow couldn't get
gedit
to open, it spits:I even tried setting
DISPLAY
- your export command had an error it said, so I used this instead:I've tried setting theDISPLAY
variable with the host's IPv4 address to no avail - it simply displays the provided address aftercannot open display:
.When I set the port to 22, nothing shows up.Of course, using the Published Applications menu works - how do I add Godot Engine to this list? I tried installing it but running it throws an error saying thatX11 Display is not available
.Okay, I included a
.desktop
file in/usr/share/applications
but when I launch Godot I get this in a dialog box:I confirmed that at this time there are no packages above version 1.6.3 for xinput for my distro, and that when I did
apt install xinput
it found this version.x2go creates it's own X display directly on the host - you can find the port via
x2golistsessions
. Then you can set the DISPLAY variable to use it: