WSL dev setup endgame
As my first two articles discussed, I have used Windows 10 with WSL 2 and Ubuntu as my development environment for Java/Node for some time now. But Ubuntu uses the Snap Store to install software so you have to have systemd running. My previous two posts showed two different ways how to set up systemd.
Getting systemd to work comes with price to pay. For all the details read my last 2 articles, but I have to say that the price is too high. So instead of solving all the issues coming from having systemd within WSL, let us try to avoid having those problems.
The main difference for this article is that we are using Debian instead of Ubuntu — as Debian is not using Snap, thus we should not need systemd.
This guide shows step by step what I did to set up a Java/Node development environment with WSL+Debian.
Windows prerequisites
We need to start with the usual preparations on the Windows side:
Do the basic installation steps for WSL 2 on Windows 10 as described here https://docs.microsoft.com/en-us/windows/wsl/install-win10
A dev setup without Docker ain’t no dev setup ;) so let’s install that as well https://docs.docker.com/docker-for-windows/wsl/
In my humble opinion Visual Studio Code is generally the best editor in 2020, but when it comes to WSL setups VSC has the unique feature to be able to edit files inside the WSL VM from the Windows side. So I strongly recommend to install it https://visualstudio.microsoft.com/
The next step is to get the Debian distribution from the Microsoft App Store: https://www.microsoft.com/en-us/p/debian/9msvkqc78pk6
I also recommend to install Windows Terminal as it is way better than the default terminal app coming with Windows and especially the possibility to auto-start the gnome-terminal makes it superior. You can install it from https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701
Finally you need an X11 Server for Windows. I would recommend VcXsrv as it is free and doesn’t have any issues https://sourceforge.net/projects/vcxsrv/
So let us make sure the X Server is running on Windows. Install and start it as described this article. Keep in mind to change the Windows Firewall!
Debian setup
If not done yet, start “Debian” from the Windows Start menu once to install it into WSL. Close the application when you see the shell.
Start Windows Terminal and select “Debian” from the profile menu, then execute
cd $HOME
to change to your home directory as Windows Terminal starts in the Windows Home directory by default. This is something we can reconfigure later on.
Continue with
sudo apt update && sudo apt -y upgrade
to install all available updates.
Let us continue to install some useful packages (at least useful for my type of development):
sudo apt install -y git tasksel net-tools exa openjdk-11-jdk maven gradle wget chromium curl gcc g++ make jq fish meld
As you see this installs commonly known packages, feel free to add/remove packages to your liking.
This guide assumes you will use fish as your shell.
To set the DISPLAY variable properly, you need to put this into your ~/.config/fish/config.fish
set -x DISPLAY (cat /etc/resolv.conf | grep nameserver | cut -d ' ' -f 2):0
I also needed to explicitly set the PATH variable in my config.fish, but if your PATH variable already looks similar, I would suggest to skip the next step. Make sure to replace <WINDOWS_USER> with your actual windows user name.
set -x PATH "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/c/Users/<WINDOWS_USER>/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/<WINDOWS_USER>/AppData/Local/Programs/Microsoft VS Code/bin"
From this point in time you can use “code” to open Visual Studio Code and of course you can “code <filename>” to just edit a file on the Linux filesystem with Visual Studio Code. If this doesn’t work, you need to open Visual Studio Code manually and install the plugin “Remote-WSL”.
Now we want to install the gnome-desktop to run UI applications.
sudo tasksel install gnome-desktop
Finally we can change the default shell from bash to fish:
chsh -s /usr/bin/fish
After closing the current Windows Terminal shell and re-opening one, you should be ready to roll in the fish shell.
You can start with one of these X11 applications:
gnome-terminal/opt/idea/bin/idea.sh &chromium &firefox &nautilus / &meld
Windows Terminal setup
To make your life easier you can change some configuration. Open the settings for Windows Terminal:
- Add a “startingDirectory”: “//wsl$/Debian/home/<DEBIAN_USER>” to change the initial directory
- You can change the defaultProfile to Debian’s UUID to avoid the first windows always creates a PowerShell
- Add a “commandline”: “wsl -d Debian — gnome-terminal && /usr/bin/fish” to automatically start the gnome terminal
Example settings:
"profiles":
{
"defaults":
{
},
"list":
[
{
"guid": "{58ad8b0c-3ef8-5f4d-bc6f-13e4c00f2530}",
"hidden": false,
"name": "Debian",
"source": "Windows.Terminal.Wsl",
"commandline": "wsl -d Debian -- gnome-terminal && /usr/bin/fish",
"startingDirectory": "//wsl$/Debian/home/oli"
}
]
}
VcXsrv setup
You can always start VcXsrv manually, but you can also create a xlaunch file to easily start the X11 Server under Windows with the right configuration. To do so create a file called “x11-startup.xlaunch” at a convenient location under Windows. Add this content:
<?xml version="1.0" encoding="UTF-8"?>
<XLaunch
WindowMode="MultiWindow"
ClientMode="NoClient"
LocalClient="False"
Display="-1"
LocalProgram="xcalc"
RemoteProgram="xterm"
RemotePassword=""
PrivateKey=""
RemoteHost=""
RemoteUser=""
XDMCPHost=""
XDMCPBroadcast="False"
XDMCPIndirect="False"
Clipboard="True"
ClipboardPrimary="False"
ExtraParams=""
Wgl="True"
DisableAC="True"
XDMCPTerminate="False"
/>
Go to C:\Users\<WINDOWS_USER_NAME>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
and create a Windows Shortcuts file here. For maximum convenience go to your Start Menu, right click the new entry "x11-startup" and click "Pin To Start".
Conclusion
This setup using WSL + X11 + Debian doesn’t require solutions for problems you should not have in the first place.
Check out this walk-through video.
I created a script to automate this initial setup for Debian.
Feel free to try it: