# WSL2

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/zh-cn/help/clion/llms.txt).

> **TL;DR**
> 本地客户端操作系统  ：Windows
>
>
>
> 远程主机操作系统  ：WSL [Linux 发行版](https://jb.gg/clion-wsl)
>
>
>
> 源代码位置  ：本地计算机
>
>
>
> 项目模型  ： [CMake](quick-cmake-tutorial.html) / [Makefile](makefiles-support.html) / [编译数据库](compilation-database.html)

> **Warning:**
> 要使用 Gradle 或 Maven 项目，请确保   远程执行代理：二进制文件   已 [启用](managing-plugins.html)。

[WSL](https://docs.microsoft.com/en-us/windows/wsl/about)（ [WSL 2](https://docs.microsoft.com/en-us/windows/wsl/wsl2-index)）——Windows Subsystem for Linux——是一个兼容层，用于在 Windows 10 及更高版本上本地运行 Linux 二进制可执行文件。 目前，它支持若干 [Linux 发行版](https://docs.microsoft.com/windows/wsl/install-win10#windows-10-fall-creators-update-and-later-install-from-the-microsoft-store)，例如 Ubuntu、OpenSUSE 和 SLES。

通过为您的项目设置  WSL 工具链 ，您可以使用来自 Linux 的工具链进行构建，并在 WSL 上运行/调试，而无需离开运行在 Windows 机器上的 CLion。

> **Note:**
> 您无需在 WSL 内安装或运行 CLion。

Procedure: 配置 WSL

1. 在 Windows 计算机上，从 [Microsoft Store](https://jb.gg/clion-wsl) 下载并安装一个 WSL 发行版（例如 Ubuntu）。

此步骤请务必使用 Windows 10 或更高版本，并安装最新的"秋季创作者更新"（最低版本 1709，构建 16299.15）。 请参阅官方指南 [Install the Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10)了解详细说明。

要使用   WSL 2  ，您的 Windows 版本应为 10 版本 18917 或更高版本。 请遵循 [这些指示](https://docs.microsoft.com/windows/wsl/wsl2-install#set-a-distro-to-be-backed-by-wsl-2-using-the-command-line)来切换分布式。

请注意，CLion 不支持   旧版 WSL  ，后者可能是在将系统升级到 Windows 10 构建 16299.15 或更高版本之前安装的。 在这种情况下，您需要更新您的 WSL 发行版。

2. 运行 Linux 发行版。

首次启动时，系统可能会提示您启用 Windows 可选功能。 在这种情况下，您需要执行以下操作：

* 以管理员身份打开 Windows PowerShell 并运行 ```SHELL Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux ```

* 重新启动您的计算机。

> **Note:**
> 如果您使用的是除 Ubuntu 之外的 Linux 发行版，请确保该发行版已安装 [iproute2](https://wiki.linuxfoundation.org/networking/iproute2) 包，或在部署 WSL 实例后手动安装它。

3. 设置 Linux 发行版环境：

安装 cmake、gcc 和/或 clang（以及可选的  build-essentials  软件包），如下所示：

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

```

Procedure: 为您的项目配置 WSL 工具链

1. 在 CLion 中，转到  `设置 | 构建、执行、部署 | 工具链` 。

2. 点击 ![加号图标](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.add.svg)以创建一个新工具链并选择   WSL  。

3. 在   工具集  字段中，选择一个可用的 WSL 发行版。 列表包括由  `wsl.exe --list` 检测到的发行版，其中包括导入的发行版。

> **Note:**
> 如果 CLion 无法找到您的 WSL 可执行文件，原因可能是 [WSL 问题](https://github.com/Microsoft/WSL/issues/2592)已在   Windows 10 版本 1803  中修复。 尝试将系统更新到版本 1803 或更高版本。

![WSL 工具链](https://resources.jetbrains.com/help/img/idea/2026.3/cl_wsl_new_toolchain.png)

等待所有工具被检测到并保存设置。

> **Tip:**
> 可以配置 CLion 在登录 (-l) shell 中执行 WSL 命令。 有关更多信息，请参阅 [此页面](advanced-settings.html#advanced-wsl)。

4. 现在要开始使用工具链，请执行以下操作：

CMake:

1.  将 WSL 工具链设置为   默认  （将其移至列表顶部）或 [创建一个关联的 CMake 配置文件](remote-projects-support.html#CMakeProfile)。

2.  [构建](build-actions.html)、 [运行](running-applications.html)和 [调试](debugging-code.html)与往常一样。

> **Tip:**
> 为了在 WSL 上运行   Valgrind  ，请确保选择与 WSL 工具链关联的 CMake 配置文件。 有关更多信息，请参阅 [此说明](memory-profiling-with-valgrind.html#valgrind-wsl)。

Makefile:

1.  在  `设置 | 构建、执行、部署 | Makefile` 中切换到 WSL 工具链。

2.  调用  `工具 | Makefile | 清理并重新加载 Makefile 项目` 。

3.  在 [本机应用程序](makefiles-support.html#create-makefile-config)配置中，使用  `\mnt\..` 表示法将   可执行文件  指向二进制文件（例如，  `\mnt\c\Users\jetbrains\CLionProjects\SimpleMakefile\runme` ）。

> **Note:**
> 请参阅 [使用 Makefile 项目时的 WSL 特性](makefiles-support.html#wsl-notes)。

## See also

### 操作指南

[Remote development overview](remote-development.html)

### 快速开始

[Quick Tutorial: Configuring CLion on Windows](quick-tutorial-on-configuring-clion-on-windows.html)

### 外部链接

[CLion Debugging Beyond the Basics - Part 3 - Beyond Local](https://blog.jetbrains.com/clion/2021/05/clion-debugging-beyond-the-basics-part-3-beyond-local) [Webinar Recording: Remote Development with CLion](https://blog.jetbrains.com/clion/2019/03/webinar-recording-remote-development-with-clion)

