前言
- 安装cocoapod,需要ruby2.2.2以上版本(版本太低需要更新)
- 安装ruby,需要rvm安装
安装rvm
//安装rvm
curl -L https://get.rvm.io | bash -s stable
//载入rvm环境(安装完成需要执行一次,后续使用terminal会自动载入)
source ~/.rvm/scripts/rvm
//通过版本命令检查是否安装成功
rvm -v
安装需要的Ruby版本
//列出已知的ruby版本
rvm list known
//安装需要版本的ruby
rvm install 2.2.4
//列出已安装的ruby版本
rvm list
//设置默认ruby版本
rvm 2.2.4 --default
可能出现的错误
在执行rvm 2.2.4 --default
时报如下错误
Error running '__rvm_make -j 1',
please read /Users/GuHaijun/.rvm/log/1509591164_ruby-2.3.4/make.log
There has been an error while running make. Halting the installation.
其原因在于没有安装Xcode的CommandLineTools工具
执行下面的代码:
xcode-select --install
安装cocoapods
- 天朝封杀,改ruby源(使用taobao源)
//添加淘宝源
gem sources -a https://ruby.taobao.org/
//删除默认源
gem sources -r https://rubygems.org/
//查看源列表
gem sources -l
//更新gem
sudo gem update --system
- 安装cocoapods
sudo gem install cocoapods
- 具体安装参考官网Guides
https://guides.cocoapods.org/using/getting-started.html
可能出现的错误
在执行sudo gem install cocoapods
时报如下错误
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
解决方法参考stackoverflow:
sudo gem install cocoapods -n /usr/local/bin
网友评论