Cocoapod安装
系统环境:macOS High Sierra 10.13.4
1、安装 RVM
1.1 开始安装
curl -L get.rvm.io | bash -s stable

等待一段时间后就可以成功安装好 RVM。
1.2 继续rvm,依次输入命令,按回车之后并没有什么反应
source ~/.bashrc
source ~/.bash_profile

1、3 查看rvm版本
rvm -v

2、用RVM升级Ruby
2.1 查看当前ruby版本
ruby -v

2.2 查看已知的ruby版本
rvm list known

2.3 安装ruby
rvm install 2.4.1

开始安装ruby,其中需要按两次回车键,确认安装“Homebrew”和“Xcode Command Line Tools”工具(如果没有安装这个两个工具,出现“-bash: _ruby: command not found”,所以通过rvm安装ruby,这样就不用自己手动安装这两个工具了)。

此过程比较耗时,期间会让你输入电脑密码,以继续安装。当出现

ruby安装完成
3、更换ruby源
3.1 查看ruby源
gem sources -l
如果是https://ruby.taobao.org源,则替换成https://gems.ruby-china.org/,因为taobao Gems 源已停止维护,现由 ruby-china 提供镜像服务

3.2 移除https://ruby.taobao.org/
gem sources --remove https://ruby.taobao.org/

3.3 替换https://gems.ruby-china.org/,并查看新源是否替换成功
gem sources -a https://gems.ruby-china.org/

4、安装cocopods
4.1 输入命令和密码
sudo gem install cocoapods

warning:如果出现这个,则输入命令:sudo gem install -n /usr/local/bin cocoapods

warning:如果安装了多个Xcode,则安装cocoapod命令:sudo xcode-select -switch/Applications/Xcode.app/Contents/Developer
,(一般需要选择最近的Xcode版本)
出现这个,说明cocoapod安装成功了。

5、安装本地库
pod setup
然后就是漫长的等待,当然,网络好的情况下会更快
warning:要查看文件下载进度的可以另外打开一个终端窗口,输入命令cd~/.cocoapodsdu -sh *
,回车再输入命令du -sh *
之后会显示已下载的文件大小,可以多次执行来监看下载进度,如果之前还有文件大小,后来变成0了,可能是网络问题,下载已经中断了,需要结束命令并从新执行 pod setup
warning:安装失败,出现 CocoaPods was not able to update the master
repo. If this is an unexpected issue and persists you can inspect it running pod repo update --verbose

解决方法一:输入命令
pod repo update --verbose
更新一下本地库,更新完之后重新输入pod setup
。
解决方法二:见https://www.jianshu.com/p/ad2a294597b6
出现Setup completed,则说明安装完成。

6、下载安装本地库完成之后可执行列命令pod search AFNetworking
检查是否可用(第一次使用时间可能要久一点)。
至此,coocapod就全部安装完毕,可以正常使用了。