关于Flutter报CocoaPods installed but it is not working的解决办法

最近在搭建Flutter环境的时候,使用flutter doctor -v出现以下警告:

[!] Xcode - develop for iOS and macOS (Xcode 13.4.1)
    ✗ CocoaPods installed but not working.
        You appear to have CocoaPods installed but it is not working.
        This can happen if the version of Ruby that CocoaPods was installed with
        is different from the one being used to invoke it.
        This can usually be fixed by re-installing CocoaPods.
      To re-install see
      https://guides.cocoapods.org/using/getting-started.html#installation for
      instructions.

提示的是:Ruby的版本和CocoaPods的版本不对应产生的问题。Ruby Version Manager(Ruby版本管理器)是用于类UNIX操作系统的软件平台,用于管理同一设备上Ruby的多个安装。如果还没有安装,可以使用下面的命令安装:

$ curl -L https://get.rvm.io | bash -s stable

然后,再使用source命令使rvm生效。

$ source ~/.bash_profile
$ source ~/.bashrc

接下来,就是使用nvm安装指定的ruby版本。安装之前可以使用下面的命令查看可用的ruby版本。

rvm list known
//安装指定版本
rvm install "ruby-3.1.2-default"

由于网络的原因,安装会比较慢,安装完成之后,可以使用ruby -v来查看是否正确安装。最后,在使用下面的命令安装cocoapods。

sudo gem install cocoapods

再次运行就正常了。

猜你喜欢

转载自blog.csdn.net/xiangzhihong8/article/details/125620679