安装 Claude Code 指南

2025-08-13

安装 Claude Code 指南

📋 安装流程概述

安装 Claude Code 分为两个主要步骤:

  1. 安装 Claude Code 的运行环境
  2. 安装 Claude Code 本身

💡 提示:如果你有代理,可以访问 GitHub 仓库,或者无需代理访问 Gitee 镜像使用一键安装脚本

🚀 Step 1: 安装运行环境

  1. 访问 Node.js 官网(无需代理)
  2. 下载并安装 Node.js(请务必选择 20 以上版本

安装完成后,NPM 会自动安装在 Node.js 的安装目录下

🔧 Step 2: 安装 Claude Code

国内网络环境复杂,你有两个选择:

方案 A: 切换国内镜像源

# 这里使用淘宝镜像源,永久生效 
npm config set registry https://registry.npmmirror.com  

补充说明

# 单次使用镜像源  
npm install lodash --registry=https://registry.npmmirror.com  

# 可选镜像源
# 腾讯云镜像:https://mirrors.cloud.tencent.com/npm/
# 华为云镜像:https://repo.huaweicloud.com/repository/npm/

配置完成后运行如下命令安装 Claude Code:

npm install -g @anthropic-ai/claude-code

方案 B: 使用代理(自行准备)

这里以代理地址 http://127.0.0.1:7890 为例:

Windows 系统

CMD - 临时代理命令:

set http_proxy=http://127.0.0.1:7890
set https_proxy=http://127.0.0.1:7890

永久配置可通过系统环境变量设置

PowerShell - 临时代理命令:

$env:http_proxy="http://127.0.0.1:7890"
$env:https_proxy="http://127.0.0.1:7890"

永久配置可通过修改 $PROFILE 文件

Mac/Unix 系统

Bash/Zsh - 临时代理命令:

export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890

永久配置可通过写入 ~/.bashrc~/.zshrc

配置完代理后,运行安装命令:

npm install -g @anthropic-ai/claude-code

✅ 安装完成

安装完成后,你就可以开始使用 Claude Code 进行 AI 辅助开发了!