1、homebrew安装(也可自行前往Homebrew)
终端执行这句指令:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2、RVM安装(即:Ruby Version Manager)
终端执行这句指令:
brew install ruby
等待几分钟升级ruby从2.6.1到3.2.+,这个时候 你输入ruby -v 其实还是2.6.1 那是因为环境变量没有指向最新的ruby库
<internal:/usr/local/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require': linked to incompatible /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/libruby.2.6.dylib - /Users/b3build/.gems/gems/date-3.3.3/lib/date_core.bundle (LoadError)
from <internal:/usr/local/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from /Users/b3build/.gems/gems/date-3.3.3/lib/date.rb:4:in `<top (required)>'
from <internal:/usr/local/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:/usr/local/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from /usr/local/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/time.rb:4:in `<top (required)>'
from <internal:/usr/local/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:/usr/local/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from /Users/b3build/.gems/gems/gh_inspector-1.1.3/lib/gh_inspector/evidence.rb:2:in `<top (required)>'
from <internal:/usr/local/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:/usr/local/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from /Users/b3build/.gems/gems/gh_inspector-1.1.3/lib/gh_inspector.rb:4:in `<top (required)>'
from <internal:/usr/local/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:/usr/local/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from /Users/b3build/.gems/gems/cocoapods-1.12.1/lib/cocoapods/user_interface/error_report.rb:5:in `<top (required)>'
from <internal:/usr/local/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
CocoaPods当前支持的Ruby版本应该是2.5或更高版本。然而,根据你的错误信息,系统中安装的Ruby版本为3.2.0,这可能是不兼容的版本。所以我们需要降级ruby到2.7。
第一步我们查找下可用的ruby:
brew search ruby
第二步安装指定的ruby
brew install ruby@2.7
第三步配置终端环境变量(使终端可以使用指定的ruby,在/Users/b3build/.zshrc,将.zshrc直接点开,然后插入第二行)
export PATH="/usr/local/opt/ruby@2.7/bin:$PATH"
3、ruby镜像源
先查看ruby镜像源
gem sources-l
替换ruby镜像源
gem sources--addhttps://gems.ruby-china.com/--removehttps://rubygems.org/
4、gem升级
因为降级ruby到2.7后,gem就和ruby的版本对上了,但是gem里面一些库需要升级,也就代表着gem需要升级到新的版本,这个是我们升级ruby到2.7.10后,调用gem install cocoapods后报的错,如下提示:需要gem升级到3.4.17
终端执行gem升级到3.4.17:
gem update --system 3.4.17
升级完后查看gem版本是否升级到3.4.17
gem -v
5、cocoapods安装
gem install cocoapods -V
经过几分钟的等待,调用pod 不在报错说明pod安装成功了