Electron is tricky to get set up on Windows Subsystem for Linux, but it can work!
Four things needed overall:
- you need WSL2, not WSL1
- you need node, of course, and that part isn't so bad
- you need to
apt install
several dependencies - you need an X Server so it can display the electron GUI over in Windows-land
Setup instructions, in order:
- Set up WSL2 via https://docs.microsoft.com/en-us/windows/wsl/install-win10
- If you have WSL1 already, I suggest making a second installation of Ubuntu etc with WSL2 beside your WSL1 so you don't mess up existing projects while you troubleshoot it all.
- Install NVM via https://github.com/nvm-sh/nvm
- Install a node version, like using
nvm install stable
- Clone your electron repo like Zettlr, and
npm install
oryarn install
things - Try to run it (
npm start
oryarn start
usually). Do you see some errors related to libraries?- The filename it can't find is a hint for a package you have to install, but with slight naming changes. Its
apt install
package name is slightly different than the filename that electron is looking for. In my cases, the underscore became a dash, and the dash between the name and version number goes away.libgdk_pixbuf-2.0
becomeslibgdk-pixbuf2.0-0
. I had the most luck googling "ubuntu libgdk" etc and then the package name showed up usually. - My latest install command:
sudo apt install libgconf-2-4 libatk1.0-0 libatk-bridge2.0-0 libgdk-pixbuf2.0-0 libgtk-3-0 libgbm-dev libnss3-dev libxss-dev
- Anyone know a better way to find these without googling? lol I'm thankful there weren't too many
- The filename it can't find is a hint for a package you have to install, but with slight naming changes. Its
- Try to run
npm start
again - does NOTHING happen? Now you need X Server!- Follow this guide to set up an X Server like VcXsrv: https://techcommunity.microsoft.com/t5/windows-dev-appconsult/running-wsl-gui-apps-on-windows-10/ba-p/1493242
- And just in case it helps, this less thorough but more canonical reference: https://wiki.ubuntu.com/WSL#Running_Graphical_Applications
- To test your X Server, I suggest testing using a non-electron app to start to isolate X Server from the rest of the issues. The first X Server article here suggests installing
sudo apt install x11-apps
and runningxcalc
as a test case.
- Now try again, and it should work!
WSL2: Ubuntu
In my case, Xvfb was required, as well.
sudo apt-get install -y xvfb
Reference: https://stackoverflow.com/a/61043049
Then run the following:
Windows
VcsXsrv Config:
On Windows, open VcsXsrv and it’ll guide you through three config screens. Here’s what to pick on each one:
Electron apps then successfully executed.