brew 设置代理 作者: Chuwen 时间: 2023-07-04 分类: macOS 评论 ## 1. 查找 `brew` 所在位置 一般路径都在 `/usr/local/bin/brew`,请记录好,后续需要使用 ```shell ➜ ~ which brew /usr/local/bin/brew ``` ## 2. 移动 `brew` 命令位置 ```shell mv /usr/local/bin/brew /usr/local/bin/brew_orig ``` ## 3. 新建一个如 `.proxy` 文件置代理 执行命令 `vim ~/.proxy.sh`,文件内容为: > 以下代理服务器地址根据自己实际情况调整 ```shell #!/bin/bash export https_proxy=http://127.0.0.1:7890 export http_proxy=http://127.0.0.1:7890 export all_proxy=socks5://127.0.0.1:7890 ``` ## 4. 新建 `/usr/local/bin/brew` 文件 执行命令 `vim /usr/local/bin/brew` 文件内容为: ```shell #!/bin/bash source ~/.proxy.sh /usr/local/bin/brew_orig "$@" ``` 并赋予可执行权限 `chmod +x /usr/local/bin/brew` ## 5. 测试使用 ```shell ➜ ~ cat $(which brew) #!/bin/bash source ~/.proxy.sh /usr/local/bin/brew_orig "$@" ➜ ~ brew --version Homebrew 4.0.26 Homebrew/homebrew-core (git revision 3112e690293; last commit 2022-07-12) Homebrew/homebrew-cask (git revision 2ae6e86efe; last commit 2023-02-16) ```