大家好,我是 immerse,一位独立开发者兼内容创作者。
• 欢迎关注我的公众号:#沉浸式趣谈,获取最新文章(更多独家内容仅在公众号发布)
• 个人网站:
https://yaolifeng.com,同步更新技术文章
• 转载请务必在文首注明作者出处及版权信息
在这里,我会持续分享关于
编程、
独立开发、
AI技术、
出海项目以及
个人成长思考等方面的内容。
如果你觉得这篇文章对你有帮助,欢迎点赞、评论、转发一键三连!你的支持是我持续创作的动力,非常感谢!
前提准备:配置 WSL2 环境
若想在 Windows 上顺利运行 Claude Code,首先需要完成 WSL2(Windows Subsystem for Linux)的安装与配置。
安装流程
启用系统功能
• 在搜索栏输入:启用或关闭 Windows 功能
• 勾选以下两项:虚拟机平台
(Virtual machine platform)、适用于 Linux 的 Windows 子系统
• 根据提示重启计算机-
配置 WSL,打开 PowerShell 执行以下命令```javascript
将 WSL 默认版本设为 2
wsl --set-default-version 2
开始安装 WSL
wsl --install
若已安装 Ubuntu,建议更新 WSL(添加 --web-download 可避免因网络问题导致的下载失败)
wsl --update --web-download
3. 等待安装完成 • 耐心等待进度条走完,即表示 WSL 安装成功
- 搜索并启动 Ubuntu
打开应用后进入终端,依次执行:```javascript安装 NVM(Node Version Manager)
curl -o- https://www.php.cn/link/a92de86fbd1ad5ecc06de4a595978a81 | bash
重新加载 bash 配置文件
source ~/.bashrc
安装最新版 Node.js LTS 版本
nvm install --lts nvm use --lts
验证是否安装成功
node --version # 应显示类似 v22.x.x npm --version # 应显示类似 10.x.x
- 全局安装 Claude Code
• 安装过程中我尝试开启代理,但频繁报错。强烈建议关闭代理后再安装javascript npm install -g @anthropic-ai/claude-code
安装完成后验证版本
claude --version
6. 配置 API 密钥和基础地址javascript编辑 .bashrc 文件
nano ~/.bashrc
添加以下环境变量(请替换为你的实际 Token)
export ANTHROPIC_AUTH_TOKEN=sk-... export ANTHROPIC_BASE_URL=https://www.php.cn/link/1dcad8cc5b82a7ef72f72716b220cf13
保存后重新加载配置
source ~/.bashrc
- 启动使用 Claude Code
• 直接输入命令:claude
并回车即可开始使用
alt textalt text
常见问题与避坑指南
- 安装时可能出现如下错误:```javascript
npm WARN using --force Recommended protections disabled.
npm WARN cleanup Failed to remove some directories [
npm WARN cleanup [
npm WARN cleanup 'C:\Users\
\AppData\Roaming\npm\node_modules\@anthropic-ai\claude-code', npm WARN cleanup [Error: EPERM: operation not permitted, rmdir 'C:\Users\ \AppData\Roaming\npm\node_modules\@anthropic-ai\claude-code\vendor\sdk\src\internal'] { npm WARN cleanup errno: -4048, npm WARN cleanup code: 'EPERM', npm WARN cleanup syscall: 'rmdir', npm WARN cleanup path: 'C:\Users\ \AppData\Roaming\npm\node_modules\@anthropic-ai\claude-code\vendor\sdk\src\internal' npm WARN cleanup } npm WARN cleanup ] npm WARN cleanup ] npm ERR! code 1 npm ERR! path C:\Users\ \AppData\Roaming\npm\node_modules\@anthropic-ai\claude-code npm ERR! command failed npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/preinstall.js npm ERR! Error: Claude Code is not supported on Windows. npm ERR! Claude Code requires macOS or Linux to run properly. npm ERR! If you are using WSL (Windows Subsystem for Linux): npm ERR! 1. Make sure you are running npm install from within the WSL terminal, not from PowerShell or CMD npm ERR! 2. If you're still seeing this message in WSL, your environment may be incorrectly reporting as Windows npm ERR! Please visit https://www.php.cn/link/c5e04ccb6be7fab8ccb9df005a075cc2 for troubleshooting information.
解决方案:务必在 WSL 的 Ubuntu 终端内执行安装命令,不要在 Windows 的 CMD 或 PowerShell 中操作。使用 NVM 管理 Node 版本也能有效减少依赖冲突。
- 若 C 盘空间不足,可将 WSL 系统迁移到其他磁盘。具体操作可参考教程:Claude Code 在 Windows 系统中安装全流程教学[1]
参考链接
[1] Claude Code 在 Windows 系统中安装全流程教学: https://www.bilibili.com/video/BV1mpMizQEUS










