An alternative development WSL 2 setup with Ubuntu GUI
You might have seen my last article “A working WSL 2 Ubuntu development setup” which uses a program called “genie” to start systemd on WSL 2.
There is an alternative approach described in this blog post which I would like to discuss here now.
While that post mainly wants to enable snap on WSL 2, it also brings systemd, thus the goal is very comparable to the approach in my first article.
Basic installation
So let’s start with executing all steps in the linked blog post including the section “/etc/bash.bashrc”.
As of this writing, the location of daemonize changed from /usr/sbin to /usr/bin, so I added a sym-link:
ln -s /usr/bin/daemonize /usr/sbin/daemonize
I also changed the file/etc/default/locale
to
LANG=en_US.UTF-8
and did a “wsl --shutdown” in the Windows PowerShell to make this change effective.
Installing Gnome
The next step is to install a GUI via
sudo apt install -y taskselsudo tasksel install ubuntu-desktop
which is similar to my last article.
X11 Server on Windows
Also see my last article in how to set up and start an X11 Server on Windows. The section “Starting VcXsrv in Windows 10” described the necessary steps.
Configuration
Add the following lines to the .profile file in your user’s home directory
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | cut -d ' ' -f 2):0export NO_AT_BRIDGE=1unset XDG_RUNTIME_DIRunset DBUS_SESSION_BUS_ADDRESS
The first line sets the DISPLAY variable so X11 forwarding to Windows works.
The second line sets a variable to suppress a warning when starting the gnome terminal.
Row three and four are also needed to start gnome terminal. Frankly I don't understand why, I just tried-and-error'ed until it worked, so any explanation is appreciated.
Fish
As I like to use fish as my Unix shell, I install it via:
sudo apt install -y fish
but the setup of systemd in this scenario depends on bash, so we keep bash as the standard shell for my user.
Instead I change the default shell just for the gnome-terminal which is my default terminal application anyway.
So start the gnome terminal via:
gnome-terminal
and go to the preferences dialog and change it to:
Known issues
- I had issues in terms of "WSL can talk properly to Windows", mainly in regards to the Unix sockets in /run/WSL and the shell variable WSL_INTEROP. If those are wrong you cannot use code (aka Visual Studio Code) from WSL anymore, which is obviously very annoying, I often had to set WSL_INTEROP manually
Conclusion
Generally this approach works as fine as the first one, but the advantages and disadvantages are different.
Pros:
- You don’t have to deal with initializing “genie” and entering those bottles (aka namespaces) — …
Cons:
- …still the basic underlying issue of a separated process tree still exists
- The issue around WSL_INTEROP was very severe for me
- Fish is not the default shell — only the gnome-terminal uses it by default