mac电脑安装cocoapods出错,以及安装最新版本ruby方法

macbook安装cocoapods时碰到一个报错:大概率是ruby的版本太低导致的

sudo gem install cocoapods
ERROR:  Error installing cocoapods:
ERROR: Failed to build gem native extension.
...
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

出现这种情况,大概率是我电脑 ruby 的版本太低了,导致不能安装最新的CocoaPods

安装flutter的环境参考官方文档:Start building Flutter native desktop apps on macOS - Flutter 中文文档 - Flutter 中文开发者网站 - Flutter

那不安装最新 CocoaPods ,指定一个低版本是否可行呢?参考 Mac Flutter环境配置 — CocoaPods not installed解决方案。

sudo gem install cocoapods -v 1.8.4

使用如上命令确实安装成功了,但在 Flutter 中启动 Xcode 就会报错,启动失败。

Warning: CocoaPods minimum required version 1.9.0 or greater not installed. Skipping pod install.

根据以上,提醒我们需要一个至少 1.9 版本的 CocoaPods,那我卸载然后继续安装 1.9 版本是否就可以了呢?

# 卸载
sudo gem uninstall cocoapods

sudo gem install cocoapods -v 1.9.4

我尝试后,发现又安装失败。所以现在的情况就只有一个办法,升级 ruby

使用 homebrew 安装新版本 ruby:

brew install ruby

会在安装完后提示两个路径:将这两个路径复制到你的命令行,重新执行一下 

 
  

我们配置新安装ruby的环境变量,不用多想,按照提示来(不要复制如下路径,复制你终端提示的命令)

echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> /Users/**/.bash_profile

export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"

export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"

source /Users/**/.bash_profile

就可以看到版本最新了:
mac电脑安装cocoapods出错,以及安装最新版本ruby方法_第1张图片 

再安装 cocoapods,如果之前有安装记得先卸载(卸载命令上面有):

# 卸载
sudo gem uninstall cocoapods

# 安装
sudo gem install cocoapods

就会提示安装成功了: 

mac电脑安装cocoapods出错,以及安装最新版本ruby方法_第2张图片 

如果上面安装后运行项目还提醒没有安装 cocoapods not installing,那就这样做:

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

 

你可能感兴趣的:(软件工具,多端开发,macos,cocoapods,ruby)