问题

如今新版本的 pod 已经是默认走 CDN 的方式,不再是 master repo 的模式,但是,依然会有这个问题.

相信大家已经感受到 pod install 速度越来越慢了,网上提供了几种解决方案,但是都没有完全解决速度慢的问题。

  1. 使用国内镜像的Specs
  2. pod install时使用命令pod install --no-repo-update

下面就来说明一下这几种方法为何没有完全解决问题

  1. 使用国内镜像的Specs
    这个只是加快了Specs下载更新速度,而且如果使用国内镜像Specs,那么 Podfile 中就必须指明使用这个Specs
  2. pod install时使用命令pod install --no-repo-update
    这个只是在 install 时不更新本地 pod 库,但如果第一次 install 还是要去 github clone 代码,一样很漫长的时间

方案

其实真正慢的原因并不在 pod 命令,而是在于 github 上的代码库访问速度慢,那么真正的解决方案就是要加快 git 命令的速度。

配置代理

下面的 1087 和 1080 都是本地代理的端口号

1
2
3
4
5
// 临时设置终端所有的下载都走代理
// 终端窗口关闭,则此代理设置就会失效
export http_proxy=http://127.0.0.1:1087;
export https_proxy=http://127.0.0.1:1087;
export ALL_PROXY=socks5://127.0.0.1:1080

或者

1
2
// 设置 git 的 http 走代理
git config --global http.proxy socks5://127.0.0.1:1080

上面的命令是给 git 设置全局代理,如果我们不希望 国内 git 也走代理,而是只需要 github 上的代码库走代理,命令如下

1
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080

如此就从根本上解决了问题。

ps:如果要恢复/移除上面设置的git代理,使用如下命令

1
git config --global --unset http.proxy

或者

1
git config --global --unset http.https://github.com.proxy