macOS / Linux 安装 Claude Code
本页在 macOS 或 Linux 上从零安装官方 Claude Code 并接入 MoaCode。
一、安装 Node.js
推荐用 NVM 管理 Node 版本:
bash
# 安装 NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
source ~/.bashrc # zsh 用户:source ~/.zshrc
# 安装最新 LTS 版本
nvm install --lts
# 验证
node -v
npm -vmacOS 也可以用 Homebrew:brew install node。
二、安装 Claude Code
bash
# 如装过旧版先卸载(未装过跳过)
npm uninstall -g @anthropic-ai/claude-code
# 可选:设置国内镜像加速
sudo npm config set registry https://registry.npmmirror.com
# 安装
sudo npm install -g @anthropic-ai/claude-code
# 验证
claude --version三、接入 MoaCode
方式一:一键配置(推荐)
登录 Dashboard,在 Quick setup 选择 Claude Code → Copy Linux/macOS,粘贴到终端运行。等价命令:
bash
curl -s https://moacode.org/setup-claude-code.sh | bash -s -- --url https://moacode.org --key 你的APIKeyTIP
脚本依赖 jq。未安装时:macOS brew install jq;Ubuntu/Debian sudo apt-get install jq。
方式二:手动配置环境变量
- 获取 API Key:Dashboard 的 API configuration 复制主 Key,或在 API management 创建专用 Key
- 写入 shell 配置(zsh 为例,bash 换成
~/.bashrc):
bash
echo 'export ANTHROPIC_AUTH_TOKEN="你的APIKey"' >> ~/.zshrc
echo 'export ANTHROPIC_API_KEY="你的APIKey"' >> ~/.zshrc
echo 'export ANTHROPIC_BASE_URL="https://moacode.org"' >> ~/.zshrc
source ~/.zshrc服务器 / SSH 场景
每次新建 SSH 会话都会重新读取 shell 配置;若你只是临时 export 而没写进 ~/.zshrc / ~/.bashrc,重连后需要重新执行 export。
四、启动使用
bash
cd 你的项目目录
claude首次启动询问是否使用检测到的 API Key,选 Yes 一路回车即可。