WSL (WSL 2) - Windows Subsystem for Linux - is a compatibility layer for running Linux binary executables natively on Windows 10. Currently, it supports several Linux distributions, such as Ubuntu, OpenSUSE, and SLES.
IntelliJ IDEA lets you create and open projects in the WSL file system, run, and debug applications in the WSL environment. You can also use local Windows-based projects and run the applications remotely in WSL with the run targets feature.
Download and install a WSL distribution (for instance, Ubuntu) from Microsoft Store.
For this step, be sure to use Windows 10 with the latest “Fall Creators Update” (minimum version 1709, build 16299.15). See the official guide Install the Windows Subsystem for Linux for instructions.
To work with WSL 2, your Windows version should be 10 build 18917 or later. Follow these instructions to switch the distributive.
Note that IntelliJ IDEA does not support legacy WSL, which you may have installed before upgrading your system to the build 16299.15 or later of Windows 10. In this case, you need to update your WSL distribution.
Upon the first launch of Ubuntu, the system may prompt you to enable the Windows optional feature. In this case, you need to do the following:
Open Windows PowerShell as Administrator and runEnable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Restart your computer.
You can create a project and store it in the WSL environment, open one from the WSL file system, and develop your projects further in WSL.
Create a new project in the WSL file system
Install the needed JDK to the WSL environment using your favorite SDK manager.
On the welcome screen, click New Project.
On the page that opens, select a type of the project you want to create and from the options on the right, select a project SDK (the JDK configured in WSL). Click Next.
On the next page, specify the name of your project and project location. The project location for WSL will show the absolute path starting with \\wsl$ to the WSL file system.
You can type the path to the project location manually or click and choose the folder in the dialog, that opens.
IntelliJ IDEA creates a project located in WSL and you can develop and build your project inside the WSL environment without leaving the IDE.
Open a project stored in the WSL file system
In IntelliJ IDEA, you can directly open a project stored in the WSL file system and work with it like with any other project.
Click Open on the Welcome screen or select from the main menu.
In the dialog that opens, select the folder in the WSL file system that contains the project to open, or type the path to the \\wsl$ project location manually.
When you run code in your project, it is run in WSL. If you open the run configuration, note that IntelliJ IDEA refers to WSL as local machine.
The results of the code execution are displayed in the Run tool window.
Configure Terminal in WSL
To run Terminal in WSL configuration, open project Settings/Preference (Ctrl+Alt+S) and go to .
wsl.exein the Shell path field and click Ok.
Switch to the Terminal tool window and type any command to inspect the output.
Use WSL to run a project in the Windows file system
Create a run configuration for WSL
From the main menu, select. Alternatively, press Alt+Shift+F10, then 0.
Select one of the supported run/debug configuration types.
From the Run on menu, under the New targets section, select WSL to add a WSL target.
When you add the WSL target, IntelliJ IDEA performs an introspection and automatically adds a path to a remote JDK in WSL, and the JDK version in the New Target: WSL dialog.
If you need to add additional information to the existing WSL target, click Manage targets… and in the Run Targets dialog, add the needed information. For example, you can select Maven or Gradle as a runtime. Click OK to save the changes.
From the main menu, click Run and select the necessary run configuration or press (Shift+F10) to run your code and check the output in the Run tool window.
You need to perform the following steps to ensure that the building of a project works properly.
Configure firewall settings
Run the Windows PowerShell as administrator.
Execute the following command to allow connections using WSL:New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
Then execute the command to renew the firewall rules:Get-NetFirewallRule | where DisplayName -ILike "idea*.exe" | Remove-NetFirewallRule
Now start the debugger session. When the Windows Firewall popup appears, select the Public networks checkbox.