首先安装Homebrew --> 再安装rvm --> 再安装ruby -> 最后安装cocoapods。
1、安装homebrew
国外:/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
国内:/bin/zsh -c "$(curl -fsSLhttps://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
遇到:Failed to connect toraw.githubusercontent.comport 443: Connection refused
解决方案:直接将国外镜像替换成国内镜像
2、安装rvm
curl -L https://get.rvm.io | bash -s stable
遇到Failed to connect to raw.githubusercontent.com port 443: Connection refused
解决方案:
修改host 文件,终端输入以下命令行:sudo vi /etc/hosts,在host文件中加入以下的IP地址配置
199.232.28.133 raw.githubusercontent.com
:wq! 强制保存
查看rvm版本:rvm -v
3、安装一个ruby版本
rvm install ruby-2.6
更换源
sudo gem update --system
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
为了验证你的Ruby镜像是并且仅是ruby-china,执行以下命令查看
gem sources -l
如果是以下结果说明正确
*** CURRENT SOURCES ***
4、安装CocoaPods
sudo gem install -n /usr/local/bin cocoapods
ERROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.
遇到报错安装 ruby 2.6 :rvm install ruby-2.6
然后直接执行pod安装命令:
sudo gem install -n /usr/local/bin cocoapods