CocoaPods安装
使用gem安装,安装命令很简单
$ sudo gem install cocoapods
如果是首次安装通常会出下面的错
ERROR: Could not find a valid gem 'cocoapods' (>= 0), here is why:Unable to download data from [https://rubygems.org/](https://rubygems.org/) - Errno::ETIMEDOUT: Operation timed out - connect(2) ([https://rubygems.org/latest_specs.4.8.gz](https://rubygems.org/latest_specs.4.8.gz))ERROR: Possible alternatives: cocoapods
据说是因为ruby的软件源rubygems.org因为使用亚马逊的云服务,被屏蔽了,需要更新一下ruby的源
$ gem sources -l (查看当前ruby的源)
$ gem sources --remove https://rubygems.org/(移除当前的ruby源)
$ gem sources -a https://ruby.taobao.org/(添加新的ruby源)
$ gem sources -l(查看ruby源替换效果,如下显示表明已经替换)
*** CURRENT SOURCES ***
https://ruby.taobao.org/
替换完ruby源重新使用安装命令
$ sudo gem install cocoapods
使用CocoaPods
1、命令行方式
pod init(用于创建Podfile文件touch Podfile也可以)
open Podfile(编辑Podfile)
pod install(安装第三方)
2、使用xcode的插件CocoaPods for Xcode(目前已经支持xcode7.2)
https://github.com/kattrali/cocoapods-xcode-plugin
下载插件项目直接运行即可,忽略报错,重新打开xcode即可在product菜单下看到CocoaPods选项,包含CocoaPods的命令如下图
不过初次使用的时候还可能存在一些问题
问题一:
无论什么命令都一直在等待,那么首先考虑可能是首次使用
可以使用pod install --verbose --no-repo-update
代替 pod install
命令
问题二:
如果使用忽略仓库更新参数报错
/Library/Ruby/Gems/2.0.0/gems/claide-0.9.1/lib/claide/command.rb:417:in `help!‘: [!] You cannot run CocoaPods as root. (CLAide::Help)
退出root权限即可
$ exit
释放权限直接执行pod install即可
问题三
如果退出还是出一堆关于***command.rb***
的问题尝试下面操作
$ sudo rm -fr ~/.cocoapods/repos/master
$ pod setup
问题四(mac升级后cocospod不可用)
cocospod安装 Operation not permitted - /usr/bin/xcodeproj
解决办法:
sudo gem install -n /usr/local/bin cocoapods
问题五
setup install慢(尤其首次使用)
$ pod install
Setting up CocoaPods master repo
出现Setting up CocoaPods master repo
,说明Cocoapods在将它的信息下载到 ~/.cocoapods
里,cd
到该目录里,用du -sh *
命令来查看文件大小,每隔几分钟查看一次
CocoaPods使用注意
1、退出root安装的时候sudo会开启root权限,首次安装最好,在安装完成执行退出root权限
$ exit
2、首次使用可能时间比较长,最好使用
$ pod install --verbose --no-repo-update
3、尽可能使用最新版本gem
$ sudo gem update --system
问题六
Specs satisfying the `SDWebImage, SDWebImage (= 4.0.0), SDWebImage (~> 3.7.6)` dependency were found, but they required a higher minimum deployment target.
删除Podfile.lock重新pod install
#######问题七、
/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/dependency.rb:308:in `to_specs': Could not find 'CFPropertyList' (< 4.0, >= 2.3.3) among 53 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=/Users/dehangan/.rvm/gems/ruby-2.2.4:/Users/dehangan/.rvm/gems/ruby-2.2.4@global', execute `gem env` for more information
from /Users/dehangan/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/specification.rb:1441:in `block in activate_dependencies'
from /Users/dehangan/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/specification.rb:1430:in `each'
from /Users/dehangan/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/specification.rb:1430:in `activate_dependencies'
from /Users/dehangan/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/specification.rb:1412:in `activate'
from /Users/dehangan/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/specification.rb:1444:in `block in activate_dependencies'
from /Users/dehangan/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/specification.rb:1430:in `each'
from /Users/dehangan/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/specification.rb:1430:in `activate_dependencies'
from /Users/dehangan/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/specification.rb:1412:in `activate'
from /Users/dehangan/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems.rb:300:in `block in activate_bin_path'
from /Users/dehangan/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems.rb:300:in `synchronize'
from /Users/dehangan/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems.rb:300:in `activate_bin_path'
from /Users/dehangan/.rvm/rubies/ruby-2.2.4/bin/pod:23:in `<main>'
可能是没有安装cocoapod安装即可