一、安装前准备
系统要求
操作系统:Linux (Ubuntu 18.04+, CentOS 7+),macOS 10.15+, Windows 10+
存储空间:至少 500MB 可用磁盘空间
安装 Node.js(已安装可跳过)
确保 Node.js 版本 ≥ 18.0
# Ubuntu / Debian 用户
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo bash -
sudo apt-get install -y nodejs
node --version
# macOS 用户
sudo xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install node
node --version
Windows 用户:
方式一:官网下载(推荐新手)
- 访问 nodejs.org ( 复制到浏览器打开 )
- 下载 LTS 版本的 Windows Installer (.msi)
- 运行安装程序,按默认设置完成安装
- 打开 PowerShell 或命令提示符验证安装:
node --versionnpm --version
方式二:使用 Chocolatey
如果您已安装 Chocolatey,在管理员 PowerShell 中运行:
choco install nodejsnode --version
方式三:使用 winget(Windows 10 1709+ / Windows 11)
在 PowerShell 中运行:
winget install OpenJS.NodeJSnode --version
二、安装Claude Code
Windows 安装
npm install -g @anthropic/claude-code
#验证安装
claude –version
进行验证,若成功安装,会显示具体的版本号信息。
Linux/macOS 安装
# 全局安装 Claude Code
sudo npm install -g @anthropic/claude-code
# 验证安装
claude --version
三、环境配置
API配置
⚠️ 注意:Claude 官方不支持中国大陆用户,推荐使用国内镜像站,使用体验完全相同。
镜像 ClaudeYY(推荐)
访问 www.claudeyy.com 获取API Key
连接镜像服务器:www.claudeyy.com/api
# 设置镜像服务器地址
export ANTHROPIC_BASE_URL=https://www.claudeyy.com/api
# 验证配置
echo $ANTHROPIC_BASE_URL
官方(暂不支持国内用户使用)
# 从 https://console.anthropic.com 获取 API Key
export ANTHROPIC_API_KEY="sk-your-key-here"
# 根据你的 shell 选择配置方式
# Bash
echo 'export ANTHROPIC_API_KEY="sk-your-key-here"' >> ~/.bashrc
source ~/.bashrc
# Zsh
echo 'export ANTHROPIC_API_KEY="sk-your-key-here"' >> ~/.zshrc
source ~/.zshrc
# Fish
echo 'set -gx ANTHROPIC_API_KEY "sk-your-key-here"' >> ~/.config/fish/config.fish
基本配置
# 修改默认设置
claude config set -g model claude-sonnet-4
claude config set -g verbose true
claude config set -g outputFormat text
# 测试安装是否成功
claude "Hello, Claude!"
claude /doctor
安全设置(可选,有一定风险)
# 禁用遥测数据收集
export DISABLE_TELEMETRY=1
# 禁用错误报告
export DISABLE_ERROR_REPORTING=1
# 禁用非必要的模型调用,节约 token
export DISABLE_NON_ESSENTIAL_MODEL_CALLS=1
# 限制工具权限
claude config set allowedTools "Edit,View"
# 跳过对话框
claude config set hasTrustDialogAccepted true
claude config set hasCompletedProjectOnboarding true
# 设置忽略文件模式
claude config set ignorePatterns ".env,.git,node_modules"