安装或升级Cocoapods失败:Failed to build gem native extension

本文介绍了解决使用Cocoapods时遇到的安装错误问题。错误提示为未能找到Ruby头文件,解决方法包括检查并设置Xcode路径。

使用Cocoapods时报错,尝试升级也报错。

$ sudo gem install cocoapods
Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
	ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20220919-8448-1x4boqd.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/include/ruby.h

You might have to install separate package for the ruby development
environment, ruby-dev or ruby-devel for example.

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-21/2.6.0/ffi-1.15.5/gem_make.out

之前一直是好的,这种情况可能是因为,系统未安装Xcode或未设置Xcode版本。另外,更新Xcode版本,也可能会导致Xcode设置重置。

# 查看当前的Xcode设置
$ xcode-select -p

可在Xcode / Preferences / Locations / Command Line Tools检查设置,或者通过下面的命令设置Xcode路径。

# 将 /Applications/Xcode.app 替换为实际路径
$ xcode-select --switch /Applications/Xcode.app
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值