--- title: 使用 mamba 和 npm 安装 Claude Code date: 2026-05-26 tags: [Claude Code, Node.js, npm, mamba] collections: [软件安装] summary: 记录使用 mamba 准备 Node.js 环境并通过 npm 安装 Claude Code 的基本流程。 draft: false featured: false --- # 使用 mamba 和 npm 安装 Claude Code 这篇笔记整理了一次 Claude Code 的安装过程,适合已经在本机使用 `mamba` 管理环境的场景。 ## 创建 Node.js 环境 先创建一个独立环境,再在其中安装 `nodejs`。 ```bash mamba create -n node mamba activate node mamba install nodejs ``` ## 使用 npm 安装 Claude Code 环境准备完成后,可以直接通过 `npm` 全局安装。 ```bash npm install -g @anthropic-ai/claude-code ``` ## 网络较慢时切换镜像 如果安装过程中遇到网络问题,可以临时切换 npm registry 进行加速,安装完成后再切回官方源。 ```bash npm config set registry https://registry.npmmirror.com npm install -g @anthropic-ai/claude-code npm config set registry https://registry.npmjs.org ``` ## 跳过首次启动引导 安装完成后,如果希望跳过首次启动时的引导和登录检查,可以在 `~/.claude.json` 中写入下面的内容: ```json { "hasCompletedOnboarding": true, "hasTrustDialogAccepted": true, "primaryApiKey": "sk-placeholder" } ``` ## 说明 上面的配置示例使用占位符形式的 `primaryApiKey`。实际使用时,按自己的认证方式和运行需求调整即可。