图文分步教程

Windows 上安装 Claude Code(WSL):从 wsl --install 到第一次会话

一份跟着真实会话走的 Windows 11 + WSL 环境下安装 Claude Code 的图解教程——启用 WSL 2、在 Ubuntu 中安装 CLI、登录并选择套餐、信任项目文件夹、读懂用量仪表。

Ubuntu terminal inside WSL on Windows showing curl -fsSL https://claude.ai/install.sh | bash followed by Claude Code successfully installed, Version 2.1.198, Location ~/.local/bin/claude and Installation complete
WSL 中 Ubuntu 里的安装横幅——Claude Code successfully installed,版本 2.1.198,位置 ~/.local/bin/claude(2026 年 7 月录制)。

约 5 分钟 · 14 个图文步骤

先说结论

在 PowerShell 里运行 wsl --install 拿到带 Ubuntu 的 WSL 2,然后在 Ubuntu 里一条命令安装 Claude Code:curl -fsSL https://claude.ai/install.sh | bash。首次运行依次选择主题、登录方式和套餐(浏览器完成),授权码回填到终端。信任项目文件夹后即可开工——Claude Code 能通过 /mnt/c 读写 Windows 文件,随时用 /cost 查看用量。官方文档也提供原生 Windows 安装(irm https://claude.ai/install.ps1 | iex),不想用 WSL 可以走那条路。

来源视频

本页每一帧画面都来自 Draeger-IT 的录屏——德语界面的 Windows 11 机器、WSL 2 + Ubuntu、安装时 Claude Code 2.1.198,录制于 2026 年 7 月。

截图带出处使用,每一步都链回视频对应秒数。德语旁白不照抄——上方文字依据屏幕内容撰写,并与 code.claude.com/docs 核对。

第 1 部分 · 在 Windows 11 上准备 WSL

Claude Code 跑在 Linux 子系统里,所以先装 WSL 2。录屏的 Windows 界面是德语——你机器上的菜单措辞可能略有差异。

  1. 1

    运行 wsl --install

    打开 PowerShell 输入 wsl --install。在没有 WSL 的机器上,这会拉取适用于 Linux 的 Windows 子系统;录屏机器已有部分组件,德语输出会提示需要启用哪个可选功能。

    Windows PowerShell on Windows 11 with wsl --install typed at the prompt and the German banner Alle Rechte vorbehalten, preparing the Windows Subsystem for Linux
    提示符是 PS C:\Users\stefa> ——这是 PowerShell,不是 CMD。看视频 0:15 处
  2. 2

    确认默认是 WSL 2

    输出里写明默认 WSL 版本是 2;录屏机器上还建议用 wsl --install --web-download 拉取组件。WSL 2 提供真正的 Linux 内核,这正是 Claude Code 和 Docker 等工具所需要的。

    Windows Terminal running wsl --install --web-download with German WSL status output confirming default version 2 and notes about the optional Windows Subsystem for Linux component
    如果已装过 WSL,wsl --version 会直接打印版本号——两种结果都算成功。看视频 0:45 处
  3. 3

    在文档里选好安装方式

    Quickstart 的 Step 1 按平台列出命令:macOS、Linux、WSL 共用 curl -fsSL https://claude.ai/install.sh | bash;Windows PowerShell 用 irm https://claude.ai/install.ps1 | iex;Windows CMD 有自己的 curl 写法。在 WSL 里要用的就是第一条。

    Claude Code Docs quickstart page at Step 1 Install Claude Code with Native Install Recommended, Homebrew and WinGet tabs, the macOS Linux WSL curl command, and separate Windows PowerShell and Windows CMD commands
    文档还链接了 VS Code 和 JetBrains IDE 集成,以后用得上。看视频 2:35 处

第 2 部分 · 在 Ubuntu 里安装 CLI

官方 Quickstart 按平台各给一条命令;在 WSL 里用的就是 macOS/Linux 那条 curl。

  1. 4

    在 Ubuntu 里运行 curl 安装脚本

    在 Ubuntu 终端里运行 curl -fsSL https://claude.ai/install.sh | bash,拿到完整成功横幅:Claude Code successfully installed,版本 2.1.198,位置 ~/.local/bin/claude,Next: Run claude --help to get started,Installation complete!然后 cd 进项目文件夹 claude-code-projekte。

    Ubuntu terminal inside WSL on /mnt/c/Users/stefa showing curl -fsSL https://claude.ai/install.sh | bash followed by Claude Code successfully installed, Version 2.1.198, Location ~/.local/bin/claude and Installation complete
    提示符 stefan@DellLaptop:/mnt/c/Users/stefa 说明 Ubuntu 正工作在挂载的 Windows 盘上。看视频 2:55 处
  2. 5

    选择终端主题

    首次运行 claude 会打开主题选择器——Choose the text style that looks best with your terminal——默认选中 Dark mode,下面还有 Hello World 实时预览。录屏保留 Dark mode 直接回车。

    Claude Code first-run theme picker titled Choose the text style that looks best with your terminal, with Dark mode selected above a green and red Hello World preview
    六种风格覆盖浅色、色盲友好和 ANSI 限色终端。看视频 3:10 处

第 3 部分 · 登录并选择套餐

首次运行 claude 会依次走完主题、登录方式、浏览器登录和套餐选择——最后把授权码回填到终端。

  1. 6

    选择登录方式

    下一屏:Claude Code 可用你的 Claude 订阅,或通过 Console 账户按 API 用量计费。三个选项:1. Claude account with subscription(Pro、Max、Team 或 Enterprise),2. Anthropic Console account(API 用量计费),3. 第三方平台(Amazon Bedrock、Microsoft Foundry 或 Vertex AI)。录屏选了第 1 项。

    Claude Code login screen listing three methods: 1. Claude account with subscription Pro Max Team or Enterprise, 2. Anthropic Console account with API usage billing, 3. third-party platform with Amazon Bedrock, Microsoft Foundry or Vertex AI
    订阅账号是最常见路径;Console 计费适合纯 API 用法。看视频 3:15 处
  2. 7

    浏览器批准,回贴授权码

    Claude Code 打印一个浏览器 URL 并等待:Paste code here if prompted。打开 URL 登录——录屏的德语浏览器显示 Anmelden,选项为 Mit Google fortfahren 和 Mit E-Mail fortfahren——Claude 会给你一个一次性授权码,贴回终端即可。

    Claude Code terminal showing the OAuth browser URL with the account part pixelated and the prompt Paste code here if prompted waiting for the authorization code
    录屏把 URL 和码打了码——两者都是会话级的,你的会不一样。看视频 3:25 处
  3. 8

    用你的账号登录

    浏览器登录页提供常用的登录方式——录屏里是 Google 账号。登录完成后会进入套餐选择页。

    Claude login page in a German browser showing Anmelden with two options, Mit Google fortfahren and Mit E-Mail fortfahren, plus the account chooser popup
    弹出账号选择浮层是因为浏览器里已有登录态。看视频 3:40 处
  4. 9

    选择 Claude 套餐

    套餐页列出 Free($0,容量有限,偶尔使用)、Pro($20/月或按年,Standard 容量,常规使用)和 Max($200,每次会话 5 倍 Pro 容量,与 Claude 协作频繁的重度用户)。已订阅的用户会跳过这一步——录屏也只走了一遍。

    Claude Support page titled Choose a Claude plan with a table listing Free at 0 dollars, Pro at 20 dollars monthly or annual marked Standard, and Max at 200 dollars with 5x Pro capacity per session
    可以先从 Free 开始,额度吃紧时再升级。看视频 4:05 处
  5. 10

    复制授权码

    选完套餐,浏览器显示授权页——录屏的德语界面写作 Authentifizierungscode,提示 Füge dies in Claude Code ein(把这段贴进 Claude Code)。复制授权码,贴回两步前等待输入的终端。

    Claude authorization page in German titled Authentifizierungscode with the instruction Füge dies in Claude Code ein and a one-time code ready to copy back into the terminal
    授权码是一次性的——过期就重启 claude 重新登录。看视频 5:00 处

第 4 部分 · 第一次会话与用量

安全提示、文件夹信任确认,以及随时可查的用量仪表。

  1. 11

    读一遍安全提示

    第一句提示词之前,Claude Code 显示两条警告:Claude can make mistakes——尤其是运行代码时务必复查——以及因提示注入风险只将它用于你信任的代码,并附安全文档链接。按 Enter 继续。

    Claude Code onboarding screen with Security notes reading Claude can make mistakes and due to prompt injection risks only use it with code you trust, ending with Press Enter to continue
    每个系统的全新安装都会显示同样的提示。看视频 5:15 处
  2. 12

    信任你的项目文件夹

    Accessing workspace 检查会点名文件夹——录屏里是 /mnt/c/Users/stefa/claude-code-projekte——并警告 Claude Code'll be able to read, edit, and execute files here,然后问:这是你创建或信任的项目吗?自己的代码选 1. Yes, I trust this folder。

    Claude Code workspace safety check reading Accessing workspace /mnt/c/Users/stefa/claude-code-projekte, warning that Claude Code will be able to read, edit, and execute files here, with options 1. Yes, I trust this folder and 2. No, exit
    /mnt/c/ 路径就是 WSL 访问 Windows 盘的方式——文件原封不动。看视频 5:30 处
  3. 13

    会话就绪

    信任文件夹后,Claude Code 打招呼——录屏显示 Welcome back Stefan,Sonnet 5 · Claude Pro——附上提示(运行 /init 创建 CLAUDE.md)、What's new 面板,以及等待第一条提示词的输入框。

    Claude Code session screen reading Welcome back Stefan with Sonnet 5 Claude Pro, Tips for getting started like Run init to create a CLAUDE.md file, and a notice that Fable 5 is now a standard part of the Max plan
    从 wsl --install 到可用提示词,一次坐下就能完成,无需重启。看视频 5:40 处
  4. 14

    用 /cost 查看用量

    随时可用 /cost 打开用量屏(录屏运行在 Claude Code v2.1.201 上):按模型列出的总成本——该账户是 claude-sonnet-5 和 claude-haiku-4-5——以及 Current session、Current week (all models) 和 Current week (Fable) 三条用量条和各自的时区重置时间。

    Claude Code v2.1.201 cost screen showing Total cost 0.3038 dollars with usage by model for claude-sonnet-5 and claude-haiku-4-5, Current session 1 percent used and Current week 0 percent used with reset times in Europe Berlin
    录屏的会话只用了 1%,当周 0%——额度按周重置。看视频 4:30 处

常见问题