安装 Claude

什么是 ClaudeCode

ClaudeCode是我们所称的 Agentic Coding Tool,简称 Coding Agent。

Read、Write、Bash、Git,模型输出到预定工具,预定工具执行任务,执行完后输出给模型作为输入,反复交互完成人们指定的任务内容。

过去几年,众多AI编程工具相继涌现,如 Github Copilot、Cursor、Windsurf、Cursor、CodeX等等。

软件工程并不会消失,但我们构建软件的方式已经改变,并将持续演进。

Coding Agent就像伐木工的 油锯,从斧头到手锯,再到油锯 电锯,工具一直在变,没人做10年软件工程师后仍然会对个简单的CRUD API的构建感到最初那样的兴奋,只会觉得无聊。这样的内容全世界的软件工程师已经写了百万千万次数十亿百亿次,LLM早就具备了输出类似代码的能力。

下载 ClaudeCode

https://code.claude.com/docs/zh-CN/overview

curl -fsSL https://claude.ai/install.sh | bash

https://downloads.claude.ai/claude-code-releases/bootstrap.sh

#!/bin/bash

set -e

# Parse command line arguments
TARGET="$1"  # Optional target parameter

# Validate target if provided
if [[ -n "$TARGET" ]] && [[ ! "$TARGET" =~ ^(stable|latest|[0-9]+\.[0-9]+\.[0-9]+(-[^[:space:]]+)?)$ ]]; then
    echo "Usage: $0 [stable|latest|VERSION]" >&2
    exit 1
fi

DOWNLOAD_BASE_URL="https://downloads.claude.ai/claude-code-releases"
DOWNLOAD_DIR="$HOME/.claude/downloads"

# Check for required dependencies
DOWNLOADER=""
if command -v curl >/dev/null 2>&1; then
    DOWNLOADER="curl"
elif command -v wget >/dev/null 2>&1; then
    DOWNLOADER="wget"
else
    echo "Either curl or wget is required but neither is installed" >&2
    exit 1
fi

# Check if jq is available (optional)
HAS_JQ=false
if command -v jq >/dev/null 2>&1; then
    HAS_JQ=true
fi

# Download function that works with both curl and wget
download_file() {
    local url="$1"
    local output="$2"
    
    if [ "$DOWNLOADER" = "curl" ]; then
        if [ -n "$output" ]; then
            curl -fsSL -o "$output" "$url"
        else
            curl -fsSL "$url"
        fi
    elif [ "$DOWNLOADER" = "wget" ]; then
        if [ -n "$output" ]; then
            wget -q -O "$output" "$url"
        else
            wget -q -O - "$url"
        fi
    else
        return 1
    fi
}

# Simple JSON parser for extracting checksum when jq is not available
get_checksum_from_manifest() {
    local json="$1"
    local platform="$2"
    
    # Normalize JSON to single line and extract checksum
    json=$(echo "$json" | tr -d '\n\r\t' | sed 's/ \+/ /g')
    
    # Extract checksum for platform using bash regex
    if [[ $json =~ \"$platform\"[^}]*\"checksum\"[[:space:]]*:[[:space:]]*\"([a-f0-9]{64})\" ]]; then
        echo "${BASH_REMATCH[1]}"
        return 0
    fi
    
    return 1
}

# Detect platform
case "$(uname -s)" in
    Darwin) os="darwin" ;;
    Linux) os="linux" ;;
    MINGW*|MSYS*|CYGWIN*) echo "Windows is not supported by this script. See https://code.claude.com/docs for installation options." >&2; exit 1 ;;
    *) echo "Unsupported operating system: $(uname -s). See https://code.claude.com/docs for supported platforms." >&2; exit 1 ;;
esac

case "$(uname -m)" in
    x86_64|amd64) arch="x64" ;;
    arm64|aarch64) arch="arm64" ;;
    *) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
esac

# Detect Rosetta 2 on macOS: if the shell is running as x64 under Rosetta on an ARM Mac,
# download the native arm64 binary instead of the x64 one
if [ "$os" = "darwin" ] && [ "$arch" = "x64" ]; then
    if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" = "1" ]; then
        arch="arm64"
    fi
fi

# Check for musl on Linux and adjust platform accordingly
if [ "$os" = "linux" ]; then
    if [ -f /lib/libc.musl-x86_64.so.1 ] || [ -f /lib/libc.musl-aarch64.so.1 ] || ldd /bin/ls 2>&1 | grep -q musl; then
        platform="linux-${arch}-musl"
    else
        platform="linux-${arch}"
    fi
else
    platform="${os}-${arch}"
fi
mkdir -p "$DOWNLOAD_DIR"

# Always download latest version (which has the most up-to-date installer)
version=$(download_file "$DOWNLOAD_BASE_URL/latest")

# Reject non-version content (e.g. an HTML error page) before it reaches the manifest URL
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
    echo "Failed to get a valid version from downloads.claude.ai (got unexpected content)." >&2
    echo "This can happen if the download service is unreachable or not available in your region - see https://www.anthropic.com/supported-countries" >&2
    exit 1
fi

# Download manifest and extract checksum
manifest_json=$(download_file "$DOWNLOAD_BASE_URL/$version/manifest.json")

# Use jq if available, otherwise fall back to pure bash parsing
if [ "$HAS_JQ" = true ]; then
    checksum=$(echo "$manifest_json" | jq -r ".platforms[\"$platform\"].checksum // empty")
else
    checksum=$(get_checksum_from_manifest "$manifest_json" "$platform")
fi

# Validate checksum format (SHA256 = 64 hex characters)
if [ -z "$checksum" ] || [[ ! "$checksum" =~ ^[a-f0-9]{64}$ ]]; then
    echo "Platform $platform not found in manifest" >&2
    exit 1
fi

# Download and verify
binary_path="$DOWNLOAD_DIR/claude-$version-$platform"
if ! download_file "$DOWNLOAD_BASE_URL/$version/$platform/claude" "$binary_path"; then
    echo "Download failed" >&2
    rm -f "$binary_path"
    exit 1
fi

# Pick the right checksum tool
if [ "$os" = "darwin" ]; then
    actual=$(shasum -a 256 "$binary_path" | cut -d' ' -f1)
else
    actual=$(sha256sum "$binary_path" | cut -d' ' -f1)
fi

if [ "$actual" != "$checksum" ]; then
    echo "Checksum verification failed" >&2
    rm -f "$binary_path"
    exit 1
fi

chmod +x "$binary_path"

# Run claude install to set up launcher and shell integration
echo "Setting up Claude Code..."
"$binary_path" install ${TARGET:+"$TARGET"}

# Clean up downloaded file
rm -f "$binary_path"

echo ""
echo "鉁� Installation complete!"
echo ""

能看到怎么下载ClaudeCode的可执行文件,中国被Anthropic禁用了。

# 获取最新版本号
https://downloads.claude.ai/claude-code-releases/latest
# 如 2.1.177

# manifest.json
https://downloads.claude.ai/claude-code-releases/$version/manifest.json
# 如 $version=2.1.177
https://downloads.claude.ai/claude-code-releases/2.1.177/manifest.json

manifest.json

{
  "version": "2.1.177",
  "commit": "6fae7a072b111776fc95ca221caac31b7439eb25",
  "buildDate": "2026-06-13T00:29:44Z",
  "platforms": {
    "darwin-arm64": {
      "binary": "claude",
      "checksum": "eb0730351be2f02b482b1855870f5877489085aac86b0c4c1db4e458d9e40ed9",
      "size": 225124512
    },
    "darwin-x64": {
      "binary": "claude",
      "checksum": "fcdc6c6679d4e1e3a0a3812f24e8b08ab73156732072c2ca5ee6248bee8313bd",
      "size": 227642800
    },
    "linux-arm64": {
      "binary": "claude",
      "checksum": "baf3926dc166215772f959e367da9784ff4c75157aaafe4524fdc79ebff984b1",
      "size": 250394248
    },
    "linux-x64": {
      "binary": "claude",
      "checksum": "ff41753634b20c869ef6a32a20863521b33d4186ac0d6a49379ab48a48395ee7",
      "size": 250480336
    },
    "linux-arm64-musl": {
      "binary": "claude",
      "checksum": "bc756f27912d993d632a5f86be9a0364fc3c1373d146a367e46c8d01d3ca1620",
      "size": 243248984
    },
    "linux-x64-musl": {
      "binary": "claude",
      "checksum": "4884b1512bf2863a85f1717eee58840b05d558568f817be71b1a116a430f4a96",
      "size": 244890672
    },
    "win32-x64": {
      "binary": "claude.exe",
      "checksum": "408ddf27d45fc6b6516843c0513072bc0f474d7bface60ae8bbbc633bef9feb2",
      "size": 245856928
    },
    "win32-arm64": {
      "binary": "claude.exe",
      "checksum": "89652ac1f73ccc3fe039a1d388af81af82608af1cac7a32b5ebc2189b8ae2d62",
      "size": 241821856
    }
  }
}

claude 可执行文件路径

https://downloads.claude.ai/claude-code-releases/$version/$platform/claude

https://downloads.claude.ai/claude-code-releases/2.1.177/
gaowanlu@gaowanludeMacBook-Pro claudecode % uname -s
Darwin

MacOS 是 Darwin

# 浏览器访问即可下载到Claude
https://downloads.claude.ai/claude-code-releases/2.1.177/darwin-arm64/claude
gaowanlu@gaowanludeMacBook-Pro claudecode % chmod +x claude
gaowanlu@gaowanludeMacBook-Pro claudecode % ./claude
Welcome to Claude Code v2.1.177
..........................................................

     *                                       █████▓▓░
                                 *         ███▓░     ░░
            ░░░░░░                        ███▓░
    ░░░   ░░░░░░░░░░                      ███▓░
   ░░░░░░░░░░░░░░░░░░░    *                ██▓░░      ▓
                                             ░▓▓███▓▓░
 *                                 ░░░░
                                 ░░░░░░░░
                               ░░░░░░░░░░░░░░░░
                                                      *
        ▗     ▖ ▖                       *
                      *
.......         ..........................................

 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
gaowanlu@gaowanludeMacBook-Pro claudecode % 

首次启动claude后,会尝试连接到 api.anthropic.com, 之后提示地区不支持

~/.claude.json 文件中添加以下内容

"hasCompletedOnboarding": true

然后再运行就可以了

设置环境变量

为claude加环境变量

gaowanlu@gaowanludeMacBook-Pro dev_dir % cat ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git" # zsh
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export PATH="$HOME/dev_dir/claudecode:$PATH"