cocoapod安装 Homebrew方式 适合国人成功率高速度快(30分钟通关)

cocoapod安装(Homebrew)

Homebrew安装

第一步:安装Homebrew

使用国内脚本-打开terminal输入以下命令

安装脚本(终端中粘贴下方命令回车)

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

卸载脚本:

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"


第二步:替换ruby源

检测ruby源:

 gem sources -l 

正常我们看到的是这样:

*** CURRENT SOURCES ***

https://rubygems.org/


移除自带的源:

gem sources --remove https://rubygems.org/

替换成国内源:

gem sources --add https://gems.ruby-china.com/

检测是否替换成功:gem sources -l 

显示:

*** CURRENT SOURCES ***

https://gems.ruby-china.com/

第三步:安装cocoapod

使用Homebrew安装CocoaPods :

brew install cocoapods

 安装完成之后:

 pod setup

查询当前Pod版本与安装版本是否一致:

brew info cocoapods

pod --version

修复版本不一致的问题:

brew link --overwrite cocoapods

下载cocoapod索引文件到本地(这里使用一定要国内地址下载):

git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git ~/.cocoapods/repos/master

pod官方源地址可能下载不下来(需要黑魔法):

git clone https://github.com/CocoaPods/Specs.git  ~/.cocoapods/repos/master

如果使用官方源也可以使用 :

pod repo update --verbose

第四步:检测是否安装成功

pod search AFNetworking

如果出现

# [!] Unable to find a pod with name, author, summary, or description matching AFNetworking

可以进入 ~/Library/Caches/CocoaPods文件夹寻找并删除search_index.json,然后重新执行

pod search AFNetworking


如果出现安装完成还是提示找不到brew和pod

command not found:brew

command not found:pod

原因是因为换成国内的源后默认路径找不到,我们需要配置路径

使用终端打开.zshrc 或者.bash_profile

open ~/.zshrc

.zshrc中加上下面这段

#intel -- intel芯片

export PATH="/usr/local/bin:/usr/local/sbin:$PATH"

#apple-- intel芯片

export PATH="/usr/local/bin:/opt/homebrew/sbin:$PATH"

再运行

source ~/.zshrc 

就可以了

常见的源:

source 'https://github.com/CocoaPods/Specs.git' 

source 'https://cdn.cocoapods.org/' 

source'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容