Mac都自带ruby,但是最好升下级
$ sudo gem update --system
移除原来的ruby源
$ gem sources --remove https://rubygems.org/
换成马云的
$ gem sources -a https://ruby.taobao.org/
淘宝的不能用了,现在用这个:(但是不知道为什么一开始是sources,现在添加是source。少了个s)
$ gem source -a https://gems.ruby-china.com/
查看是不是只剩下马云的
$ gem sources -l
安装
$ sudo gem install cocoapods
OSX 10.11安装时默认的安装地址貌似不好用了,所以就安装到/usr/local/bin里
$ sudo gem install -n /usr/local/bin cocoapods
别忘了添加一下PATH
$ export PATH=/usr/local/bin:$PATH
安装好后,接下来进行配置
先搜个afn试试看
$ pod search AFNetworking
能够得到很多结果
再用xcode创建一个新项目就先叫test吧。
然后cd到那个项目目录下,例如
$ cd /Users/JasonLiu/Desktop/test
然后做
$ pod init
这样系统就帮你建了Podfile文件,并且里面有内容
用文本编辑器打开这个文件,修改里面的内容,加入刚才搜索到的afn的名称以及版本
# Uncomment this line to define a global platform for your project # platform :ios, '8.0' # Uncomment this line if you're using Swift # use_frameworks! target 'test' do pod 'AFNetworking', '~> 3.0.1' end
下一步就是
$ pod install
然后大功告成,如果想添加更多其它库,就在Podfile里输入其它的库的名称以及版本,然后再运行一下pod install