打开终端
移除现有 Ruby 默认源
$ gem sources --remove https://rubygems.org/
使用新的源
淘宝源还是能用,就是比较慢:
$ gem sources -a https://ruby.taobao.org/
//备用地址:更新为新的源地址
//$ gem sources -a https://gems.ruby-china.org/
验证新源是否替换成功
$ gem sources -l //查看当前的源地址
安装 CocoaPods
$ sudo gem install cocoapods
$ pod setup
#######备注:苹果系统升级 OS X EL Capitan 后安装改为:
$ sudo gem install -n /usr/local/bin cocoapods
$ pod setup
更新 gem
$ sudo gem update --system
新建工程,并在终端用 cd 指令到文件夹内
$ pod search 第三方
新建 Podfile 文件
$ pod init
编辑 Podfile 文件,并写入要添加的第三方库
platform:ios, '8.0'
pod 'AFNetworking', '~> 2.3.1'<-------第三方
导入第三方库
$ pod install
$ pod install --verbose --no-repo-update
错误解决方法:
错误一
[!] The `AllBlue [Debug]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.debug.xcconfig'. This can lead to problems with the CocoaPods installation
Use the $(inherited) flag, or
Remove the build settings from the target.
[!] The `AllBlue [AutoDebug]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.autodebug.xcconfig'. This can lead to problems with the CocoaPods installation
Use the $(inherited) flag, or
Remove the build settings from the target.
[!] The `AllBlue [Release]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.release.xcconfig'. This can lead to problems with the CocoaPods installation
Use the $(inherited) flag, or
Remove the build settings from the target.
[!] The `AllBlue [AutoRelease]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.autorelease.xcconfig'. This can lead to problems with the CocoaPods installation
-
造成的原因是:target的设置覆盖了 pod的设置
解决办法:
- 在
Build Settings -> Other linker flags 中添加$(inherited)
- 修改完毕后,终端执行
pod install
- 重新打开工程
错误二
遇到 Error installing pods:activesupport requires Ruby version >=2.2.2
-
造成的原因是:没有安装 RVM baby 版本管理器
解决办法:
1.安装 RVM baby 版本管理器
$curl -L get.rvm.io | bash -s stable
- 安装完成 出现下面这行提示以下
In case of problems: https://rvm.io/helpandhttps://twitter.com/rvm_io
- 执行
$source ~/.bashrc
$source ~/.bash_profile
- 测试是否安装正常
$rvm -v
- //提示以下
rvm 1.27.0 (latest) by Wayne E. Seguin, Michal Papis[https://rvm.io/]
2.用RVM升级Ruby查看当前ruby版本
$ruby -v
$rvm list known
- //提示以下
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.8]
[ruby-]2.2[.4]
[ruby-]2.3[.0]
[ruby-]2.2-headruby-head
# for forks use: rvm install ruby-head---url https://github.com/github/ruby.git --branch 2.2
# JRuby
- 安装ruby 2.2.2 执行
$rvm install 2.2.2
- 如果打印
ruby-2.2.2 - #validate archive
ruby-2.2.2 - #extract
ruby-2.2.2 - #validate binary
ruby-2.2.2 - #setup
ruby-2.2.2 - #gemset created /Users/abc/.rvm/gems/ruby-2.2.2@global
ruby-2.2.2 - #importing gemset
/Users/abc/.rvm/gemsets/global.gems..............................
ruby-2.2.2 - #generating global wrappers........
ruby-2.2.2 - #gemset created /Users/abc/.rvm/gems/ruby-2.2.2
ruby-2.2.2 - #importing gemsetfile /Users/abc/.rvm/gemsets/default.gems
evaluated to empty gem list
ruby-2.2.2 - #generating default wrappers........
Updating certificates in '/etc/openssl/cert.pem'.
mkdir: /etc/openssl: Permission denied
mkdir -p "/etc/openssl" failed, retrying with sudo
LiuWenqiang password required for 'mkdir -p /etc/openssl':
and sudo mkdir worked
3.说明安装成功,继续安装CocoaPods
$ sudo gem install cocoapods
$ pod setup