今天将系统升级至Ventura后发现Flutter iOS项目上跑不起来,报一下错误

Ignoring ffi-1.15.5 because its extensions are not built. Try: gem pristine ffi --version 1.15.5

查资料说要卸载重新安装Cocoapods

sudo gem install cocoapods

然后又得到了以下错误:

You don't have write permissions for the /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0 directory.

又是谷歌一顿折腾后发现似乎是系统自带Ruby版本过旧的问题,使用Homebrew安装新版本的Ruby即可解决。

1、安装Ruby

brew install ruby

2、查看ruby版本

ruby -v

3、安装完成后发现依旧是2.6版本,需要设置环境变量

vim ~/.zshrc

ARM机型粘贴以下代码:

if [ -d "/opt/homebrew/opt/ruby/bin" ]; then
  export PATH=/opt/homebrew/opt/ruby/bin:$PATH
  export PATH=`gem environment gemdir`/bin:$PATH
fi

x86机型粘贴以下代码:


if [ -d "/usr/local/opt/ruby/bin" ]; then
  export PATH=/usr/local/opt/ruby/bin:$PATH
  export PATH=`gem environment gemdir`/bin:$PATH
fi

4、再次查看版本是否为安装的新版本

source ~/.zshrc
ruby -v
  1. 重新安装Cocoapods
sudo gem install cocoapods

然后进入运行flutter doctor,若没有错误项目应该就能跑起来了。

  1. 如果pod install出现权限问题
warning: Insecure world writable dir /opt/homebrew/bin in PATH, mode 040777

设置目录权限即可

sudo chmod -R go-w /opt/homebrew/bin
sudo chmod -R go-w /opt/homebrew

参考:
https://mac.install.guide/ruby/13.html
https://blog.csdn.net/liuwenchang1234/article/details/127635234

标签: none