无法在 macOS 10.15.7 终端安装 CocoaPods。

3
当我在终端上像这样输入:
sudo gem install -n /usr/local/bin cocoapods

它向我显示了这样的错误:

Building native extensions. This could take a while...

错误:安装CocoaPods时出错:ERROR: 无法构建gem本地扩展。

current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/ext/ffi_c

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20201203-2632-pfzsbj.rb extconf.rb 检查 ffi.h... *** extconf.rb 失败 *** 无法创建 Makefile,可能是由于缺少必要的库和/或头文件。请查看 mkmf.log 文件以获取更多详细信息。您可能需要配置选项。

提供的配置选项: --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:在try_do中:编译器无法生成可执行文件。(RuntimeError)你需要先安装开发工具。从/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in block in try_compile' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in with_werror' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in try_compile' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in block in have_header' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in block in checking_for' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in block (2 levels) in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in open' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in block in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in open' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in checking_for' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in have_header' from extconf.rb:10:in system_libffi_usable?' from extconf.rb:42:in `'

若要查看此扩展失败的原因,请检查mkmf.log,该文件位于以下位置: /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.13.1/mkmf.log
extconf 失败,退出码为 1。
宝石文件将保留在 /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1 中供检查。结果记录在 /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.13.1/gem_make.out 中。
之后我尝试输入:
pod setup --verbose

它会显示以下错误:

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

请帮我解决这个问题,让我能像升级到MacOS Catalina 10.15.7之前那样使用Cocoapods。

1
你正在使用系统自带的 Ruby,这是个不好的选择。安装 rbenv 来掌控你的 Ruby 环境。同时确保 Xcode-select 和命令行工具已正确设置。请查看我的 https://www.biteinteractive.com/how-to-get-started-with-pods/ 获取完整的指南。 - matt
@matt,你的文章是正确的。 - Sarimin
1个回答

1
我建议在遇到这个错误时使用Homebrew来安装CocoaPods。
如果你还没有它,请运行:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

然后您可以安装CocoaPods:
brew install cocoapods

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