快速结论
macOS 终端默认不继承 HTTP 系统代理。最简便的方法是在 `~/.zshrc` 中添加 `proxy` / `unproxy` 快捷函数指向 Clash 本地混合端口(默认 `7897` 或 `7890`),或者直接开启客户端 TUN 模式。
详细配置步骤
1. 查看本地代理监听端口
打开 Clash Verge Rev(默认混合端口常为 `7897` 或 `7890`)或 v2rayN,在「设置」确认 HTTP 与 SOCKS5 混合端口号。
2. 临时在当前终端窗口生效
在 Clash 状态栏点击「复制环境变量」,或在终端执行:`export https_proxy=http://127.0.0.1:7897 http_proxy=http://127.0.0.1:7897 all_proxy=socks5://127.0.0.1:7897`。
3. 写入 ~/.zshrc 永久快捷命令
在 `~/.zshrc` 添加 `alias proxy='export all_proxy=socks5://127.0.0.1:7897 https_proxy=http://127.0.0.1:7897 http_proxy=http://127.0.0.1:7897'` 与 `unproxy` 取消命令,执行 `source ~/.zshrc`。
4. 验证终端出口连通性
运行 `curl -I https://www.google.com` 或 `brew update`,返回 `HTTP/2 200` 即说明命令行代理生效。
常见问题与排错技巧
- `ping` 命令使用 ICMP 协议,不走 HTTP/SOCKS 代理,测试代理通断请用 `curl` 而非 `ping`。
- 若使用 `ssh [email protected]` 协议而非 HTTPS,需额外在 `~/.ssh/config` 配置 `ProxyCommand`。