Ubuntu系统下安装Claude Code

一、参考资料

【超详细】Claude Code Ubuntu平台完整部署指南-CSDN博客

二、安装Claude Code

温馨提示:Ubuntu系统下安装Claude Code,其步骤与Windows平台类似,本文仅记录关键步骤。

详细步骤请参考:Windows系统下快速体验Claude code-CSDN博客

1. 更新系统环境

bash 复制代码
sudo apt-get update
sudo apt-get upgrade

2. 安装node.js

下载地址:NodeSource

根据系统版本,选择合适的Node.js版本。

bash 复制代码
sudo apt-get install -y curl

curl -fsSL https://deb.nodesource.com/setup_26.x | sudo -E bash -

sudo apt-get install -y nodejs

检查是否安装成功:

bash 复制代码
node --version
npm --version

输出示例:

bash 复制代码
yoyo@yoyo:/media/sda3/workspace$ node --version
v26.3.0
yoyo@yoyo:/media/sda3/workspace$ npm --version
11.16.0

3. 安装Claude Code Cli

bash 复制代码
sudo npm install -g @anthropic-ai/claude-code

输出示例:

bash 复制代码
yoyo@yoyo:/media/sda3/workspace$ sudo npm install -g @anthropic-ai/claude-code

changed 2 packages in 2m
npm warn allow-scripts 1 package has install scripts not yet covered by allowScripts:
npm warn allow-scripts   @anthropic-ai/claude-code@2.1.160 (postinstall: node install.cjs)
npm warn allow-scripts
npm warn allow-scripts Run `npm approve-scripts --allow-scripts-pending` to review, or `npm approve-scripts <pkg>` to allow.

如果安装失败,则切换为国内镜像源:

bash 复制代码
sudo npm config set registry https://registry.npmmirror.com

检查是否安装成功:

bash 复制代码
claude --version

4. 配置环境变量

bash 复制代码
sudo mkdir -p ~/.claude
sudo gedit ~/.claude/settings.json

添加以下内容(以 DeepSeek-V3.2 模型为例):

json 复制代码
{
  "env": {
    "ANTHROPIC_API_KEY": "sk-你的真实APIKey",
    "ANTHROPIC_BASE_URL": "https://platform.deepseek.com",
    "ANTHROPIC_MODEL": "DeepSeek-V3.2"
  },
  "model": "DeepSeek-V3.2"
}

5. 启动 Claude

bash 复制代码
# 创建工作空间
mkdir ~/claude_code
cd ~/claude_code

# 启动
claude

三、FAQ

Q:Note: Claude Code might not be available in your country. Check supported countries at https://anthropic.com/supported-countries

bash 复制代码
Welcome to Claude Code v2.1.160
..........................................................

     *                                       █████▓▓░
                                 *         ███▓░     ░░
            ░░░░░░                        ███▓░
    ░░░   ░░░░░░░░░░                      ███▓░
   ░░░░░░░░░░░░░░░░░░░    *                ██▓░░      ▓
                                             ░▓▓███▓▓░
 *                                 ░░░░
                                 ░░░░░░░░
                               ░░░░░░░░░░░░░░░░
       █████████                                        *
      ██▄█████▄██                        *
       █████████      *
.......█ █   █ █..........................................

 Unable to connect to Anthropic services

 Failed to connect to api.anthropic.com: ERR_BAD_REQUEST

 Please check your internet connection and network settings.

 Note: Claude Code might not be available in your country. Check supported
 countries at https://anthropic.com/supported-countries

解决方法 :修改 ~/.claude.json 文件,末尾添加一行:

json 复制代码
"hasCompletedOnboarding": true
相关推荐
苏灿烤鱼44 分钟前
连庄+2,729,空降榜眼只+440
rust·openai·agent
SeaDhdhdhdhdh9 小时前
MCP Server 搭建与使用指南
java·ai·agent·mcp
李姆斯9 小时前
为啥Agent在coding表现这么好,但是在别的领域就是差的不少?
前端·agent·ai编程
nix.gnehc9 小时前
工具表之外 -- 派生、注入与两条原语
agent
uncle_ll10 小时前
大模型量化落地全解:原理、实操、效果对比与评估调优指南
大模型·llm·模型评估·量化·ptq
HIT_Weston12 小时前
181、【Agent】【OpenCode】TuiThreadCmd(类型增长)(编译&运行时)
人工智能·agent·opencode
爱炼丹的James13 小时前
从技术名词堆积到知识图谱:如何建立自己的大模型技术体系
人工智能·llm·知识图谱
DeepAgent14 小时前
AI Agent 工程实践(31):Agent 如何部署
agent
苏灿烤鱼15 小时前
官方终端 Agent 空降登顶,为什么最新版还是 alpha?
agent