Setup and run IntelliJ in WSL2

Purpose of article

There are plenty of resources online, this is an article for my future reference and keep track of what worked for me.

Setup

  1. Install XMing

Key Configuration

  1. Instead of run Xming directly, go for XLaunch, and check no Access Control

2. In WSL, export the DISPLAY with command in your shell:

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk ‘{print $2; exit;}’):0

You might also be able to check the address directly from Xming log file:

and then run follow command in your shell:

export DISPLAY=172.26.0.1:0

With the first approach, one can just add that export command into ~/.bashrc so everytime you open the WSL2 shell, it would be executed.

Execute IntelliJ

run following command:

sh /path/to/intellij/idea/folder/bin/idea.sh
It opens !!!!! YEAH~

I normally use following command but it throw error:

. /path/to/intellij/idea/folder/bin/idea.sh

Also side effect of using . that throw error is the shell got terminated

Useful Reference

Install IntelliJ

Advanced guide for configure WSL2 and X11 forward

To access files between WSL2 and Windows

What might not be needed

Some reference say open firewall for the Xming (or other X Server like program), I did added the rule, but after disabling the rule and it still work fine, so I guess it’s not strictly necessary?