Running Elixir Observer on wsl2

June 19, 2019

I had a occasion to test WSL2. I must say it’s working better than I expected. Docker isn’t supported that great but that’s another story.

If you’ve tried to run :observer.start from IEx in WSL2, you’ve probably encountered this error:

  1. In WSL2 console, set this export:
export DISPLAY=localhost:0

This will tell X11 programs where to display (:0 is the first local display that was started). I recommend you to add this line to your .bashrc (or any other shell), so you don’t have to remember next time you open WSL2.

  1. Open Cygwin terminal and run this command:
startxfce4 -- -listen tcp

This should open Xfce windows manager. Again, best to keep this as an alias. At that point you should see Xfce desktop.

  1. Go to Xfce desktop and open xterm (Programs -> run -> type xterm) and run:
xhost +localhost

This will allow any local programs to access X.

  1. Go back to WSL2 console and run IEx
iex(1)> :observer.start
:ok

I hope that helps :)