claude安装终端代理
# Claude Code 安装踩坑复盘(v2rayN / 代理协议不匹配)
# 结论先说
这次安装卡死/失败的根因是:把 SOCKS5 端口当成 HTTP 代理端口配置了,导致 claude install 的网络请求走代理时出现 协议不匹配,表现为卡住或报错。
# 1) 现象
执行安装时卡在类似输出不动:
Installing Claude Code native build latest...
或者直接失败:
The socket connection was closed unexpectedlyFailed to fetch version ... : protocol mismatch
# 2) 一开始为什么误判“网络问题”
- 直接
curl不走代理访问storage.googleapis.com是 OK 的(DNS/TLS/HTTP 都正常)。 - 但
claude install走了终端环境里的代理,而代理配置错了,所以只有它失败/卡住。
# 3) 关键证据:安装进程在连本机代理端口
用 lsof 看到 claude install 在连:
localhost:10808
这说明它不是“卡下载源”,而是在通过 本地代理出网。
# 4) 根因:代理端口协议搞反了
我的终端环境变量当时是:
http_proxy=http://127.0.0.1:10808
https_proxy=http://127.0.0.1:10808
all_proxy=http://127.0.0.1:10808
1
2
3
2
3
但 10808 实际是 SOCKS5(不是 HTTP 代理)。
验证方式(能返回 HTTP/2 200 说明 10808 确实是 SOCKS5):
curl -Iv --socks5-hostname "127.0.0.1:10808" \
"https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases/latest"
1
2
2
因此:
claude install把http://127.0.0.1:10808当 HTTP 代理用时,会出现 protocol mismatch 或 socket closed。
# 5) 解决:在 v2rayN 开启 HTTP 代理端口,并让安装走 HTTP 代理
v2rayN 后来开启了 HTTP 代理端口(例如 10809),测试能看到:
HTTP/1.1 200 Connection established
说明 HTTP CONNECT 可用:
curl -Iv -x "http://127.0.0.1:10809" --connect-timeout 5 --max-time 30 \
"https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases/latest"
1
2
2
然后让 claude install 用正确的 HTTP 代理端口(不要再指向 10808):
HTTP_PROXY="http://127.0.0.1:10809" HTTPS_PROXY="http://127.0.0.1:10809" \
http_proxy="http://127.0.0.1:10809" https_proxy="http://127.0.0.1:10809" \
/Users/kc/.claude/downloads/claude-2.1.92-darwin-x64 install --force
1
2
3
2
3
最终成功输出:
Claude Code successfully installed!Location: ~/.local/bin/claude
# 6) 安装后顺手修的一个小问题(PATH)
安装完成后提示:
~/.local/bin不在 PATH
按提示加到 ~/.zshrc:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc
1
验证:
which claude
claude --version
1
2
2
# 7) 以后避免再踩坑的检查清单
- 先看代理变量(尤其别把 SOCKS 端口写成
http://...):
env | egrep -i 'https?_proxy|all_proxy|no_proxy'
1
用 curl 验证端口协议:
- SOCKS:
curl --socks5-hostname 127.0.0.1:PORT https://... - HTTP:
curl -x http://127.0.0.1:PORT https://...
- SOCKS:
某些程序只支持 HTTP 代理:这时必须启用 HTTP 端口(如 10809),不要强行用
ALL_PROXY=socks5h://...。
# 8) 本机终端代理控制命令(v2rayN:SOCKS=10808,HTTP=10809)
# 8.1 一次性检查当前代理变量
env | egrep -i '^(http|https|all)_proxy=|^(HTTP|HTTPS|ALL)_PROXY=|^NO_PROXY=|^no_proxy='
1
# 8.2 临时对单条命令开启 SOCKS5(不污染当前 shell)
env ALL_PROXY="socks5h://127.0.0.1:10808" all_proxy="socks5h://127.0.0.1:10808" \
curl -sS https://ipinfo.io/ip
1
2
2
# 8.3 临时对单条命令开启 HTTP 代理(给只支持 HTTP proxy 的程序)
env HTTP_PROXY="http://127.0.0.1:10809" HTTPS_PROXY="http://127.0.0.1:10809" \
http_proxy="http://127.0.0.1:10809" https_proxy="http://127.0.0.1:10809" \
ALL_PROXY="http://127.0.0.1:10809" all_proxy="http://127.0.0.1:10809" \
curl -sS https://ipinfo.io/ip
1
2
3
4
2
3
4
# 8.4 常驻别名(写进 ~/.zshrc)
# v2rayN ports
export PROXY_SOCKS_PORT=10808
export PROXY_HTTP_PORT=10809
# SOCKS5(默认更通用)
alias proxy_on='unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY; export ALL_PROXY="socks5h://127.0.0.1:${PROXY_SOCKS_PORT}"; export all_proxy="$ALL_PROXY"'
# HTTP(给只支持 HTTP proxy 的程序)
alias proxy_on_http='unset ALL_PROXY all_proxy; export http_proxy="http://127.0.0.1:${PROXY_HTTP_PORT}"; export https_proxy="$http_proxy"; export HTTP_PROXY="$http_proxy"; export HTTPS_PROXY="$http_proxy"; export ALL_PROXY="$http_proxy"; export all_proxy="$http_proxy"'
# 关闭代理
alias proxy_off='unset ALL_PROXY all_proxy http_proxy https_proxy HTTP_PROXY HTTPS_PROXY'
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
加载配置:
source ~/.zshrc
1
# 8.5 验证是否真的走代理(看出口 IP)
curl -sS https://ipinfo.io/ip
1
# 8.6 端口协议快速自检(避免把 SOCKS 端口写成 http_proxy)
- SOCKS5 端口(10808)验证:
curl -Iv --socks5-hostname "127.0.0.1:10808" --connect-timeout 5 --max-time 15 https://ipinfo.io/ip
1
- HTTP 端口(10809)验证:
curl -Iv -x "http://127.0.0.1:10809" --connect-timeout 5 --max-time 15 https://ipinfo.io/ip
1
编辑 (opens new window)
上次更新: 2026/04/06, 15:04:00