使用Ruby安装Cocoapods时出现错误

7

我尝试这样安装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.14.2/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 ./siteconf20210206-1353-ybitkb.rb extconf.rb
*** 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
    --without-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=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
    --with-ffi_c-dir
    --without-ffi_c-dir
    --with-ffi_c-include
    --without-ffi_c-include=${ffi_c-dir}/include
    --with-ffi_c-lib
    --without-ffi_c-lib=${ffi_c-dir}/lib
    --enable-system-libffi
    --disable-system-libffi
    --with-libffi-config
    --without-libffi-config
    --with-pkg-config
    --without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in `block in try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:672:in `try_ldflags'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1832:in `pkg_config'
    from extconf.rb:9:in `system_libffi_usable?'
    from extconf.rb:42:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.14.2/mkmf.log

extconf failed, exit code 1

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

基本上就是这样

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': 编译器无法生成可执行文件。(RuntimeError)您必须先安装开发工具。

我需要先安装哪些开发工具?已经安装了xCode,以及Xcode命令行工具。 我的操作系统版本是OS X 10.15.7,Xcode已经更新到最新版本。

2个回答

16

或者说...

brew install cocoapods


这就是正确的答案。使用Homebrew安装CocoaPods再简单不过了。 - Reinier Garcia

11

几个小时后终于搞定了。 我按照这个说明进行操作,并做了一些改动。

  1. 确保已安装brew,如果没有,则执行以下命令: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

  2. 将Shell设置为 zsh curl -L http://install.ohmyz.sh | sh

或者设置PATH

  1. eval "$(rbenv init -)"

  2. 安装Ruby版本管理器 brew update brew install rbenv ruby-build

  3. 安装Ruby rbenv install 2.6 # 我使用系统默认版本号,因为我不确定是否会影响我的OS X系统版本。 rbenv global 2.6 rbenv rehash

  4. 将其添加到您的zsh配置文件中 echo 'eval "$(rbenv init -)"' >> ~/.zshrc source ~/.zshrc

对我来说,这样做就可以了。所有其他的东西,如安装Xcode,接受Xcode许可协议,安装Xcode命令行工具都不能解决问题。


我也遇到了同样的问题,但这个解决方案对我有效。 - Igr Pn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接