CLion 2024.1 Help


WSL (WSL 2) – Windows Subsystem for Linux – is a compatibility layer for running Linux binary executables natively on Windows 10 and later. Currently, it supports several Linux distributions, such as Ubuntu, OpenSUSE, and SLES.

With WSL toolchain set up for your project, you can build using a toolchain from Linux, and run/debug on WSL, without leaving CLion running on your Windows machine.

Configure WSL

  1. Download and install a WSL distribution (for instance, Ubuntu) from Microsoft Store.

    For this step, be sure to use at least Windows 10 or later 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 CLion 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.

  2. Run the Linux distribution.

    Upon the first launch, 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 run

      Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
    • Restart your computer.

  3. Set up the Linux distribution environment:

    Install cmake, gcc, or/and clang (and optionally build-essentials package), as follows:

    sudo apt-get update sudo apt-get install cmake gcc clang gdb build-essential

Configure a WSL toolchain for your project

  1. In CLion, go to Settings | Build, Execution, Deployment | Toolchains.

  2. Click plus icon to create a new toolchain and select WSL.

  3. In the Toolset field, select one of the available WSL distributions. The list includes the distributions detected by wsl.exe --list, which includes the imported ones.

    WSL toolchain

    Wait for all the tools to be detected and save the settings.

  4. Now to start using the toolchain, do the following:

    1. Set the WSL toolchain as default (move it to the top of the list) or create an associated CMake profile.

    2. Build, run, and debug as usual.

    1. Switch to the WSL toolchain in Settings | Build, Execution, Deployment | Makefile.

    2. Call Tools | Makefile | Clean and Reload Makefile Project.

    3. In the Native Application configuration, point Executable to the binary using the \mnt\.. notation (for example, \mnt\c\Users\jetbrains\CLionProjects\SimpleMakefile\runme).

Firewall configuration

You need to perform the following steps to ensure that the building of a project works properly.

Configure firewall settings

  1. Run the Windows PowerShell as administrator.

    Restore firewalls to default
  2. Execute the following command to allow connections using WSL: New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow

  3. Then execute the command to renew the firewall rules: Get-NetFirewallProfile -Name Public | Get-NetFirewallRule | where DisplayName -ILike "IntelliJ IDEA*" | Disable-NetFirewallRule

  4. Now start the debugger session. When the Windows Firewall popup appears, select the Public networks checkbox.

    Allow public networks
Last modified: 07 June 2024