CocoaPods安装详细步骤

2021-12-16  本文已影响0人  燃_火

1.查询Ruby的源地址

gem source -l
查询结果: CURRENT SOURCES 冰本.png

2.移除系统Ruby源

gem sources --remove https://rubygems.org/
显示结果: httpsrubygems.oxg removed from sources.png

3.更换为国内Ruby镜像源

gem sources --add https://gems.ruby-china.com/

再查询一下是否添加成功

gem source -l
成功则显示结果: CURRENT SOURCES.png

4.安装cocoapods

sudo gem install -n /usr/local/bin cocoapods
显示错误: ERROR.png

表示可能需要升级ruby版本
方式一:
(1)安装rvm(逐步运行命令)

curl -L get.rvm.io | bash -s stable

source ~/.bashrc

source ~/.bash_profile

安装ruby

rvm install 3.0.3

设置为默认版本

rvm use 3.0.3 --default

再进行之前的cocoapods安装

方式二:
(1)安装HomeBrew

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
执行完毕显示成功: Brew自动安裝程序远行究成.png

重启终端

(2)安装ruby

brew install ruby

查看当前使用的ruby路径(也有可能homebrew安装的ruby不是你是用的ruby,仍然在用系统ruby操作)

which ruby
正确使用brew安装的ruby,会显示: opthomebrewoptrubybinruby.png

如果不是正确的路径,进行一下操作:(逐步运行命令)

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安装版本,路径是否为brew安装路径。
成功后再进行之前的cocoapods安装:

sudo gem install -n /usr/local/bin cocoapods

安装完毕,验证一下:

pod setup
成功则显示: Setup completed.png
上一篇下一篇

猜你喜欢

热点阅读