一.遇到问题到解决问题的过程
xuleideAir:~ xulei$ pod setup
Setting up CocoaPods master repo
$ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
Cloning into 'master'...
remote: Enumerating objects: 138, done.
remote: Counting objects: 100% (138/138), done.
remote: Compressing objects: 100% (107/107), done.
error: RPC failed; curl 56 SSLRead() return error -36 51.00 KiB/s
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
Cloning into 'master'...
remote: Enumerating objects: 138, done.
remote: Counting objects: 100% (138/138), done.
remote: Compressing objects: 100% (107/107), done.
error: RPC failed; curl 56 SSLRead() return error -36 51.00 KiB/s
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
xuleideMacBook-Air:~ xulei$ sudo gem uninstall cocoapods
YAML safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0).
Remove executables:
pod, sandbox-pod
in addition to the gem? [Yn]
Removing pod
Removing sandbox-pod
Successfully uninstalled cocoapods-1.6.1
xuleideMacBook-Air:~ xulei$ sudo gem install -n /usr/local/bin cocoapods --pre
YAML safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0).
ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR: You must add /O=Digital Signature Trust Co./CN=DST Root CA X3 to your local trusted store
Fetching: cocoapods-core-1.7.0.beta.2.gem (100%)
Successfully installed cocoapods-core-1.7.0.beta.2
Fetching: cocoapods-1.7.0.beta.2.gem (100%)
Successfully installed cocoapods-1.7.0.beta.2
Parsing documentation for cocoapods-core-1.7.0.beta.2
Installing ri documentation for cocoapods-core-1.7.0.beta.2
Parsing documentation for cocoapods-1.7.0.beta.2
Installing ri documentation for cocoapods-1.7.0.beta.2
2 gems installed
xuleideMacBook-Air:~ xulei$ pod setup
Setting up CocoaPods master repo
$ /usr/bin/git clone https://github.com/CocoaPods/Specs.git --progress --
master
Cloning into 'master'...
remote: Enumerating objects: 210, done.
remote: Counting objects: 100% (210/210), done.
remote: Compressing objects: 100% (165/165), done.
error: RPC failed; curl 56 SSLRead() return error -9806 1.36 MiB/s
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git --progress -- master
Cloning into 'master'...
remote: Enumerating objects: 210, done.
remote: Counting objects: 100% (210/210), done.
remote: Compressing objects: 100% (165/165), done.
error: RPC failed; curl 56 SSLRead() return error -9806 1.36 MiB/s
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
xuleideMacBook-Air:~ xulei$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Password:
xuleideMacBook-Air:~ xulei$ pod setup
Setting up CocoaPods master repo
$ /usr/bin/git clone https://github.com/CocoaPods/Specs.git --progress --
master
Cloning into 'master'...
remote: Enumerating objects: 228, done.
remote: Counting objects: 100% (228/228), done.
remote: Compressing objects: 100% (176/176), done.
Receiving objects: 65% (1894469/2914567), 254.12 MiB | 2.84 MiB/s
error: RPC failed; curl 56 SSLRead() return error -9806
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git --progress -- master
Cloning into 'master'...
remote: Enumerating objects: 228, done.
remote: Counting objects: 100% (228/228), done.
remote: Compressing objects: 100% (176/176), done.
error: RPC failed; curl 56 SSLRead() return error -9806 2.84 MiB/s
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
xuleideMacBook-Air:~ xulei$ sudo xcode-select -switch /Applications/Xcode.app
Password:
xuleideMacBook-Air:~ xulei$ pod setup
Setting up CocoaPods master repo
$ /usr/bin/git clone https://github.com/CocoaPods/Specs.git --progress --
master
Cloning into 'master'...
remote: Enumerating objects: 228, done.
remote: Counting objects: 100% (228/228), done.
remote: Compressing objects: 100% (179/179), done.
remote: Total 2914567 (delta 71), reused 121 (delta 34), pack-reused 2914339
Receiving objects: 100% (2914567/2914567), 623.93 MiB | 2.56 MiB/s, done.
Resolving deltas: 100% (1746077/1746077), done.
Checking out files: 100% (314129/314129), done.
Setup completed
二.安装过程
- 升级Ruby环境
sudo gem update --system
- 更换Ruby镜像,先移除后添加
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
- 查看当前镜像
gem sources -l
- 安装CocoaPods
sudo gem install cocoapods
OS X更新到10.11后,CocoaPods的安装和以前有了点不同
以前安装cocoapods的时候用的是这句:
sudo gem install cocoapods
现在要改成这句:
sudo gem install -n /usr/local/bin cocoapods
查看cocoapods版本
pod --version
删除cocoaPod
sudo gem uninstal cocoapods
- 安装第三方库的索引目录
pod setup
这里可能需要等很久,并且报错,比如刚开始我的安装过程就是一波三折
错误示例
正确示例
解决办法:
1.输入以下命令:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
pod setup
如果还有错
2.输入以下命令:
sudo xcode-select -switch /Applications/Xcode.app
pod setup
我一直到了这一步才解决问题
三.使用Pod install
创建示例
- 新建一个空的文件,创建在工程的最外面,命名一定要是Podfile
- 输入以下内容
target '工程名称' do
pod '第三方库名称'
end
- 关闭工程,打开终端,找到该工程文件,进入pod install
//假设工程文件在桌面
cd Desktop
cd 工程名
//可以用ls检测工程里面是某有Podfile文件
//没有就说明你的Podfile没有创建在工程的最外面
//不会成功 强烈建议创建在工程的最外面
//否则就要在Podfile文件里面添加工程路径
pod install
补充:
新的使用:
在终端进入当前这个工程目录 cd
pod init 创建Podfile文件
双击 打开Podfile文件 在文件里面添加需要导入的第三方库
例如:
pod 'ProgressHUD'
pod 'MJExtension'
在终端进入Podfile所在的目录 使用pod install 安装第三方库
创建Podfile
修改Podfile文件内容
输入想要的内容