更换源
sudo gem update --system
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
查看更换源结果
gem sources -l
*** CURRENT SOURCES ***
https://gems.ruby-china.com/
需要注意
rvm -v
和ruby -v
的版本
安装 cocoapods
sudo gem install cocoapods
安装成功
如果终端出现上面的提示,表示安装成功。到这里还剩最后一步,还需执行命令:
pod setup
image.png
1、更改终端的配置,找到终端简介,勾选Rosetta
找到终端
勾选Rosetta
2、创建文件夹.cocoapods
和repos
,创建.cocoapods
时,需要打开显示隐藏文件夹cms+shift+.
快捷键,然后创建。
创建文件夹
3、设置repos
文件夹Git初始化,即,在repos
文件路径下
pod repo remove master
cd ~/.cocoapods/repos
git init
git clone --depth 1 https://github.com/CocoaPods/Specs.git master
rm ~/Library/Caches/CocoaPods/search_index.json
pod search AFNetWorking
问题总结
1、pod search AFNetworking 报错
~ % pod search AFNetworking
Setup completed
[!] Unable to find a pod with name, author, summary, or description matching `AFNetworking`
image.png
1、解决问题
创建一个cocoa pods 的项目
使用 cocoa pods 的项目
2、链接GitHub 超时 ping github.com
ping github.com
解决办法
1、找到 github.com 的 IP 地址 ping github.com
访问 https://www.ipaddress.com
在展示的输入框中输入 github.com 及 github.global.ssl.fastly.net
分别查询获取对应的 ip 地址
image.png
MAC 解决方案
sudo vi /etc/hosts
添加
140.82.113.3 github.com
image.png
3、问题
Cloning spec repo `cocoapods` from `https://github.com/CocoaPods/Specs.git`
[!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `cocoapods`.
You can try adding it manually in `/Users/hj/.cocoapods/repos` or via `pod repo add`.
image.png
解决版本
sudo rm -fr ~/.cocoapods/repos/master
4、问题
Analyzing dependencies
[!] Couldn't determine repo type for URL: `https://github.com/CocoaPods/Specs.git`: Net::OpenTimeout
image.png
解决1: 注释掉 podfile 文件中的
#source 'https://github.com/CocoaPods/Specs.git'
解决2:
- podfile文件中指定 source 源为 master:
source 'https://github.com/CocoaPods/Specs.git'
- 执行
pod repo remove trunk
移除trunk
源
执行完后,pod search
就都正常了!