Skip to content

Claude Code 使用教程 (Linux)

1. 安装 Node.js LTS

以 Debian/Ubuntu 为例,使用 Nodesource 提供的脚本安装 Node.js。

shell
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

安装完成后验证版本:

shell
node --version

2. 安装 Claude Code CLI

通过 npm 全局安装 CLI,必要时在命令前添加 sudo。

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

3. 配置环境变量

如果之前使用过 Claude CLI,建议先删除旧配置以确保环境变量生效:

shell
rm -rf ~/.claude

临时设置:

shell
ANTHROPIC_BASE_URL="https://kicode.chat/api/claude"
ANTHROPIC_AUTH_TOKEN="您的 KiCode API Key"

写入 ~/.bashrc:

bash
echo 'export ANTHROPIC_BASE_URL="https://kicode.chat/api/claude"' >> ~/.bashrc
echo 'export ANTHROPIC_AUTH_TOKEN="您的 KiCode API Key"' >> ~/.bashrc
source ~/.bashrc

4. 运行 Claude

重新加载 Shell 配置后即可执行:

shell
claude