我试图将cocoapods安装到运行OSX 10.9.1(新Mavericks)的MacBook Pro上,键入gem install cocoapods后,我得到以下错误:

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

        "/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby" -rubygems /usr/local/rvm/gems/ruby-1.9.3-p194/gems/rake-10.1.1/bin/rake RUBYARCHDIR=/Users/rangreenberg/gems/gems/xcodeproj-0.14.1/ext RUBYLIBDIR=/Users/rangreenberg/gems/gems/xcodeproj-0.14.1/ext
/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for -std=c99 option to compiler... *** extconf.rb failed ***
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.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:491:in `block in try_compile'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:443:in `with_werror'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:491:in `try_compile'
    from extconf.rb:24:in `block in <main>'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from extconf.rb:23:in `<main>'
rake aborted!
Command failed with status (1): [/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/...]

Tasks: TOP => default => ext
(See full trace by running task with --trace)


Gem files will remain installed in /Users/rangreenberg/gems/gems/xcodeproj-0.14.1 for inspection.
Results logged to /Users/rangreenberg/gems/gems/xcodeproj-0.14.1/ext/xcodeproj/gem_make.out

当前回答

我得到这个错误,必须完全重新安装cocoapods来修复它。最后工作。也许这个解决方案适用于其他任何人。

sudo rm -rf home_folder/.cocoapods/

之后,又做了一次

pod setup

从零开始安装我的库,一切正常。

希望能有所帮助!

其他回答

当在iOS目录下运行pod install后试图在Flutter应用程序中设置GoogleMaps时,出现了同样的初始问题。

运行pod安装时出现以下错误:

zsh: /usr/local/bin/pod: bad interpreter: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: no such file or directory

接下来,在运行sudo gem install cocoapods之后,会导致另一个类似于error: error installing cocoapods: error: Failed to build gem native extension的错误。

ERROR:  Error installing cocoapods:
    ERROR: Failed to build gem native extension.

kevin建议安装Xcode开发工具:

xcode-select --install

在强调需要安装工具时,系统在运行pod install命令时再次产生与以前相同的错误。

通过拆卸和重新安装来刷新工具成为了下一个目标。 使用以下命令移除工具:

rm -rf /Library/Developer/CommandLineTools

再次安装xcode开发工具,使用:

xcode-select --install

然后,sudo gem install cocoapods和pod install运行成功。

我在macOS Catalina上也遇到了同样的问题。尽管使用Homebrew安装可以工作,但我只是好奇为什么gem安装cocoapods会失败,即使这是他们官方文档中首选或提到的安装方法。

我尝试了上面几乎所有的解决方案,可能也有一些其他的,我在谷歌搜索这个问题时发现的。

最后今天我删除了Xcode 12.4,我已经,并重新安装,实际上是出于其他原因。出于好奇,我再次尝试gem install cocoapods,现在它工作了,并安装cocoapods,与官方文档中提到的方式相同。

错误:错误安装cocoapods:错误:未能建立gem本地扩展

首先安装Ruby版本管理器rvm:

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

然后使用

source ~/.rvm/scripts/rvm 

然后安装最新版本的ruby:

rvm install ruby-2.7.2

然后流这个(你的终端)输出。

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/nec/.zprofile 

然后使用

eval "$(/opt/homebrew/bin/brew shellenv)"

最后再次尝试安装cocoapods:

sudo gem install cocoapods

以前的解决方案对我都没用。

我的情况是一个新的干净安装的macOS Catalina + XCODE;

碰巧在安装可可豆之前,我必须首先运行Xcode(在第一次运行中,Xcode设置机器与工具);

在那之后,可可豆荚就正常了。

我通过以下步骤解决这个问题:

1:rvm install 2.0.0

2: rvm列表 * ruby-1.9.3-p545 [x86_64] => ruby-2.0.0-p451 [x86_64]

3:rvm 2.0.0 -default

4:豆荚更新