Running IntellijIdea on WSL2

Categories: devenv, wsl2

Anyone that has been experimenting with WSL2 (also WSL1) knows that the integration with Visual Studio Code is really great, but even with the extensions that it provides for Java I believe that it still lacks a little bit compared with other java IDEs.

I know that running X11 on WSL2 isn’t a big deal, and this information is readily available on the internet, no more than a couple of google searches away. But I haven’t seen any consolidated guide for the WSL2 users as well as IntelliJ users.

So people have tried to just map a WSL2 folder on windows or vice-versa, therefore accessing their projects from an Intellij installed natively on windows. In general, it isn’t a recommendable approach for 2 reasons, the inter system access isn’t fast (it is faster to map WSL2  folders as network maps than accessing the mounted windows folders) and access rights.

The other problem with such an approach is that you lose the ability to access the console from inside of the IDE.

Having that said so far the best approach is to simply install Intellij inside of your Linux distribution on WSL2 and connect it to an X Server on windows. For this guide, I will be using VcXsrv but any X Server on windows would do.

The first step is to install IntelliJ on your Ubuntu distribution:

# Download the IntellijIdea
curl -L --output ideaIU.tar.gz https://download.jetbrains.com/idea/ideaIC-2020.1.2.tar.gz

# Extract the tar on a folder, IntellijIdea page recomends on /opt but can be done in any folder
tar -xzf ideaIU.tar.gz -C /opt

Make sure that you X Server is running on Windows, on VcXsrv I usually set that to Multiple windows, Start no client and I disable access control.

Before starting IntellijIdea you need to export the display configuration on Linux, for that you should do the following:

# The following line is only valid for WSL2, if you are using WSL1 the export of the DISPLAY env variable is different
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
export LIBGL_ALWAYS_INDIRECT=1

After that you are ready to start IntellijIdea:

# Assuming that you installed IntellijIdea on /opt, notice that if you download a different version the folder name maybe different
/opt/idea-IC-201.7846.76/bin/idea.sh

At the end of this process, you should be able to see IntellijIdea as a window in your Windows but everything will be running from inside the Linux on WSL2, including the folder structure and terminal.

Here are the reference to some pages that helped me to do it and come up with this post:

Btw if you are using windows and haven’t installed Windows Terminal app you should check it out: https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701

«
»
  • “`
    export DISPLAY=$(awk ‘/nameserver / {print $2; exit}’ /etc/resolv.conf 2>/dev/null):0
    export LIBGL_ALWAYS_INDIRECT=1
    “`


Leave a Reply

Your email address will not be published. Required fields are marked *