1.查询Ruby的源地址
$ gem source -l
查询结果:
CURRENT SOURCES *** https://rubygems.org
2.移除系统Ruby源
$ gem sources --remove https://rubygems.org
显示结果:
https://rubygems.org removed from sources
3.更换为国内Ruby镜像源
$ gem sources --add https://gems.ruby-china.com
再次查询是否添加成功
$ gem source -l
成功显示结果:
*** CURRENT SOURCES *** https://gems.ruby-china.com
4.安装cocoapods
$ sudo gem install -n /usr/local/bin cocoapods
显示错误:
ERROR: Error installing cocoapods: There are no versions of cocoapods-core (= 1.11.3) compatible with your Ruby & RubyGems. Maybe try installing an older version of the gem you're looking for? cocoapods-core requires Ruby version >= 2.6. The current ruby version is 2.5.0.
5.提示需要升级ruby版本
方式一:
(1)安装HomeBrew
$ /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
(2)安装ruby
$ brew install ruby
$ which ruby
显示的还是系统ruby,不是homebrew安装的ruby
/usr/local/bin/ruby
echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc export LDFLAGS="-L/usr/local/opt/ruby/lib" export CPPFLAGS="-I/usr/local/opt/ruby/include" source ~/.zshrc
再次查看ruby版本是否为brew安装版本
opt/homebrew/opt/ruby/bin/ruby
6.成功后再进行之前(步骤4)的cocoapods安装
$ sudo gem install -n /usr/local/bin cocoapods
7.安装完成后进行pod setup
$ pod setup
此时会立马显示Setup completed,说明setup是不成功的。
Setup completed
$ cd ~/.cocoapods/repos/
9.如果没有repo文件夹则创建
$ mkdir -p ~/.cocoapods/repos/
10.查看当前仓库的信息
$ pod repo
显示 0repos则表示没有仓库
11.将当前国外的创建移除
$ pod repo remove master
12.将Coding上的通过git克隆到本地并修改文件夹的改名为master
$ git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master
13.最后更新一下就行了
pod repo update