Contents

Intellij IDEA from WSL2

Running GUI application from WSL2 terminal

Intellij IDEA does not have plugin such as Visual Studio Code Remote Development, nevertheless it is possible to run linux GUI applications directly from WSL2 terminal by installing an X Server for Windows.

Install Windows X Server


Install VcXsrv that is an open-source and frequently updated Windows X Server (it will be the provider of graphics resources and keyboard/mouse events), then start it as follow:

  • Use multiple windows

/post/2020/10/idea-in-wsl2/img/VcXsvr.png

  • Do not start client

/post/2020/10/idea-in-wsl2/img/VcXsvr-2.png

  • Check disable access control or add -ac into the additional parameters, it will avoid permission denied error when trying to run a GUI application.

/post/2020/10/idea-in-wsl2/img/VcXsvr-3.png

  • Then you can save the configuration in order to reuse it later to launch VcXsvr directly with the right configuration.

/post/2020/10/idea-in-wsl2/img/VcXsvr-4.png

Windows firewall settings


Check that the Windows firewall settings are correctly configured, it must have both public and private checked for VcXsvr windows xserver.

Settings are accesibles from Windows settings > Update and security > Windows Securities > Firewall and network protection > Allow an application through firewall

WSL2 terminal configuration


The WSL2 terminal must be configured to set and export the DISPLAY environnment variable to use the Windows host’s IP of WSL2. The IP can be retrieve from the file /etc/resolv.conf that is generated by WSL2. Add the following lines into the .bashrc file to export needed variables

1
2
export LIBGL_ALWAYS_INDIRECT=1
export DISPLAY="`grep nameserver /etc/resolv.conf | sed 's/nameserver //'`:0"

Launch VcXsvr, then verify it works correctly by launching xeyes, install it if it is not already done.

/post/2020/10/idea-in-wsl2/img/Xeyes.png

Install IntelliJ on WSL2


Install the following dependencies, such as you should have all needed libraries to run Jetbrains Toolbox and IntelliJ.

1
sudo apt install libcups2 libpangocairo-1.0-0 libatk-adaptor libxss1 libnss3 libxcb-keysyms1 x11-apps libgbm1

I suggest to use Jetbrains Toolbox to install and update IntelliJ version.

Install Jetbrains Toolbox

Download JetBrains Toolbox with the following command:

1
wget -cO jetbrains-toolbox.tar.gz "https://data.services.jetbrains.com/products/download?platform=linux&code=TBA"

Then extract the file jetbrains-toolbox.tar.gz into a folder and launch the application, then install Intellij IDEA community edition.

/post/2020/10/idea-in-wsl2/img/Jetbrains-toolbox.png

I advice to enable the “Shell Scripts” feature from Jetbrains Toolbox settings such as scripts will be generated into a folder of your choose (for instance ~/dev/tools/jb). Thanks to this script, it will be easy to launch IntelliJ IDEA.