由于gem的更新引起 cocospod的一些安装步骤发生了一些变化。
1.首先更换Ruby的镜像地址来访问CocoaPods,打开终端输入以下命令:
(1)gem sources --remove https://rubygems.org/
(2)gem sources -a https://ruby.taobao.org/
(3)gem sources -l
查看是否更换成功,终端显示如下字段则为更新成功
*** CURRENT SOURCES ***
https://ruby.taobao.org/
2.检查CocoaPods的版本
pod --version
升级或安装最新版本(目前版本1.0.1)
注意:如果cocoapods已经是1.0.1版本,则跳过该步骤直接进入第三个步骤。
升级命令:sudo gem update -n /usr/local/bin --system
更新gem:sudo gem update --system
安装命令:sudo gem install -n /usr/local/bin cocoapods
pod安装:pod setup
pod setup <span style="font-family: 'microsoft yahei'; background-color: rgb(255, 255, 255);">第一次安装完成可能要一个小时左右,所以要耐心等待,如果这一步完成了,那么恭喜你已经成功安装了CocoaPods。想知道自己有没有安装完成,可以在终端输入以下命令:</span>
pod --version
显示出版本就说明成功了。
For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.1.0.beta.1
Setup completed
新建Podfile: touch Podfile
打开Podfile: open -a Xcode Podfile
platform:ios, '8.0'
target "YYKitWeiBoDemo" do
pod 'YYKit', '~> 1.0.7'
end
高版本必须写
target
target "YourProjectName" do
pod install
可能遇到的错误提示及解决方法:
Error 1:
Error fetching http://ruby.taobao.org/:
bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
解决方案:把安装流程中 $ gem sources -a http://ruby.taobao.org/
改为:$ gem sources -a https://ruby.taobao.org/
Error 2:
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
解决方案:苹果系统升级 OS X EL Capitan 后会出现的插件错误,将安装流程 5.安装 CocoaPods 的 sudo gem install cocoapods
改为 sudo gem install -n /usr/local/bin cocoapods
Error 3:
[!] Unable to satisfy the following requirements:
- `AFNetworking (~> 2.3.1)` required by `Podfile`
Specs satisfying the `AFNetworking (~> 2.3.1)` dependency were found, but they required a higher minimum deployment target.
解决方案:Podfile 文件 中 platform:ios, ‘8.0’ 后边的 8.0 是平台版本号 ,一定要加上
Error4:
――――――――――MARKDOWN TEMPLATE ――――――――――
[!] Oh no, an error occurred.
Search for existing github issues similar to yours:
https://github.com/CocoaPods/CocoaPods/search?q=%28%2FUsers%2FMAXJ%2F.cocoapods%2Frepos%2Fmaster%2FCocoaPods-version.yml%29%3A+mapping+values+are+not+allowed+in+this+context+at+line+3+column+4&type=Issues
If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new
Don't forget to anonymize any private data!
解决方案:
$ sudo rm -rf ~/.cocoapods/repos/master
$ pod setup
Ignoring json-1.8.2 because its extensions are not built. Try: gem pristine json --version 1.8.2
Ignoring json-1.8.3 because its extensions are not built. Try: gem pristine json --version 1.8.3
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /Library/Ruby/Gems/2.0.0/gems/sass-3.4.15/.yardopts
https://github.com/sass/sass/issues/1768 卸载当前版本
sudo gem uninstall cocoapods
下载旧版本
sudo gem install cocoapods -v 0.25.0
如何同时使用不同版本的Cocoapods
1、安装指定版本Cocoapods
sudo gem install cocoapods -v 0.35.0
2、使用指定版本Cocoapods
pod _0.35.0_ install, pod _0.38.2_ install
在stackoverflow搜到的解释是这样的,
This is happening because Apple has enabled rootless on the new install,也就是说在10.11系统上苹果已经启用无根的安装。在这种情况下,如果你使用如下的命令:
sudo gem install cocoa pods -v
就会出现这样的提示:
ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/pod。
为了解决上面提到的问题,以及Cocoapods在OS X 10.11系统上的正常使用,我们需要在命令行输入这样一句话,
sudo gem install -n /usr/local/bin cocoapods