macOS 终端命令行(Git / Brew / npm)配置代理教程
直接结论:macOS 系统代理默认不会自动注入终端环境变量。最简单的做法是在代理客户端复制本地端口环境变量命令(例如 `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`),或写入 `~/.zshrc` 为其设置按需开启的快捷别名。
一、在 ~/.zshrc 添加一键开关别名
不建议永久写死全局终端代理,否则连接内网仓库时会报错。推荐在 `~/.zshrc` 增加 `proxy_on` 与 `proxy_off` 两个函数别名,随用随开。
二、Git SSH 22 端口走代理技巧
HTTP 环境变量仅对 `https://` 协议仓库有效;若使用 `git@github.com:` SSH 协议,需要在 `~/.ssh/config` 中配合 `nc -X 5 -x 127.0.0.1:7897 %h %p` 配置 `ProxyCommand`,或在客户端开启 TUN 模式。
参考资料来源
- OpenSSH ProxyCommand 规范
- Git & Homebrew 代理环境变量文档
相关延伸阅读与同栏目推荐
- VS Code & Git 开发者代理指南
- macOS Gatekeeper 安全提示处理
- Windows 客户端使用教程(Clash Verge Rev / v2rayN)(使用教程 · Windows)
- Android 安卓客户端安装与订阅配置教程(使用教程 · Android)
- iOS 苹果客户端(Shadowrocket)使用教程(使用教程 · iOS)
- macOS 客户端安装与系统代理配置教程(使用教程 · macOS)