Gem:Ext::BuildError: ERROR: Failed to build gem native extension on Mac

Posted

技术标签:

【中文标题】Gem:Ext::BuildError: ERROR: Failed to build gem native extension on Mac【英文标题】: 【发布时间】:2021-08-14 16:27:55 【问题描述】:

我是一名初级程序员。我不知道这个问题。

首先,我想在 Jekyll 中使用这个主题“https://github.com/cotes2020/jekyll-theme-chirpy” 于是,我按照说明在“https://jekyllrb.com/docs/installation/macos/”这个站点下载了Gem、Ruby等。

但是,Ruby 有问题...

 
bagjun-yeong@bagjun-yeong-ui-MacBookPro UCDAyoung.github.io % bundle install
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Using public_suffix 4.0.6
Using bundler 2.2.17
Using mercenary 0.4.0
Using colorator 1.1.0
Using eventmachine 1.2.7
Using http_parser.rb 0.6.0
Using ffi 1.15.1
Using forwardable-extended 2.6.0
Using concurrent-ruby 1.1.8
Following files may not be writable, so sudo is needed:
  /Library/Ruby/Gems/2.6.0
  /Library/Ruby/Gems/2.6.0/build_info
  /Library/Ruby/Gems/2.6.0/cache
  /Library/Ruby/Gems/2.6.0/doc
  /Library/Ruby/Gems/2.6.0/extensions
  /Library/Ruby/Gems/2.6.0/gems
  /Library/Ruby/Gems/2.6.0/plugins
  /Library/Ruby/Gems/2.6.0/specifications
Using racc 1.5.2
Using rainbow 3.0.0
Using liquid 4.0.3
Using rouge 3.26.0
Using safe_yaml 1.0.5
Using unicode-display_width 1.7.0
Using jekyll-paginate 1.1.0
Using nokogiri 1.11.5 (arm64-darwin)
Using ethon 0.14.0
Using i18n 1.8.10
Using sassc 2.4.0
Using rb-inotify 0.10.1
Using pathutil 0.16.2
Using terminal-table 2.0.0
Using rb-fsevent 0.11.0
Using typhoeus 1.4.0
Using jekyll-sass-converter 2.1.0
Using listen 3.5.1
Using addressable 2.7.0
Using jekyll-watch 2.2.1
Using yell 2.2.2
Using rexml 3.2.5
Using parallel 1.20.1
Using em-websocket 0.5.2
Using nokogiri 1.11.5 (x86_64-darwin)
Using kramdown 2.3.1
Using kramdown-parser-gfm 1.1.0
Using jekyll 4.2.0
Using jekyll-archives 2.2.1
Using jekyll-redirect-from 0.16.0
Using jekyll-seo-tag 2.7.1
Using jekyll-sitemap 1.4.0
Using jekyll-theme-chirpy 4.0.1 from source at `.`
Fetching nokogumbo 2.0.5


Your user account isn't allowed to install to the system RubyGems.
  You can cancel this installation and run:

      bundle config set --local path 'vendor/bundle'
      bundle install

  to install the gems into ./vendor/bundle/, or you can enter your password
  and install the bundled gems to RubyGems using sudo.

  Password: 


Your user account isn't allowed to install to the system RubyGems.
  You can cancel this installation and run:

      bundle config set --local path 'vendor/bundle'
      bundle install

  to install the gems into ./vendor/bundle/, or you can enter your password
  and install the bundled gems to RubyGems using sudo.

  Password: 

我认为是重叠的原因是终端要求我输入两次密码来安装gem。

Installing nokogumbo 2.0.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/var/folders/h5/pv309pys7cd7_k058rl0wgx40000gn/T/bundler20210526-4419-9z2i9nnokogumbo-2.0.5/gems/nokogumbo-2.0.5/ext/nokogumbo
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210526-4419-z9tg1b.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)
/Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:160:in `require': cannot load such file -- nokogiri/nokogiri
(LoadError)
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:160:in `rescue in require'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:149:in `require'
    from /Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.5-arm64-darwin/lib/nokogiri/extension.rb:25:in `rescue in <top (required)>'
    from /Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.5-arm64-darwin/lib/nokogiri/extension.rb:4:in `<top (required)>'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
    from /Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.5-arm64-darwin/lib/nokogiri.rb:11:in `<top (required)>'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:160:in `require'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:160:in `rescue in require'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:149:in `require'
    from extconf.rb:4:in `<main>'
/Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require': cannot load such file -- nokogiri/nokogiri (LoadError)
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
    from /Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.5-arm64-darwin/lib/nokogiri/extension.rb:25:in `rescue in <top (required)>'
    from /Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.5-arm64-darwin/lib/nokogiri/extension.rb:4:in `<top (required)>'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
    from /Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.5-arm64-darwin/lib/nokogiri.rb:11:in `<top (required)>'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:160:in `require'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:160:in `rescue in require'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:149:in `require'
    from extconf.rb:4:in `<main>'
/Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require':
dlopen(/Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.5-arm64-darwin/lib/nokogiri/2.6/nokogiri.bundle, 0x0009): could not use
'/Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.5-arm64-darwin/lib/nokogiri/2.6/nokogiri.bundle' because it is not a compatible arch -
/Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.5-arm64-darwin/lib/nokogiri/2.6/nokogiri.bundle (LoadError)
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
    from /Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.5-arm64-darwin/lib/nokogiri/extension.rb:6:in `<top (required)>'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
    from /Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.5-arm64-darwin/lib/nokogiri.rb:11:in `<top (required)>'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:160:in `require'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:160:in `rescue in require'
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:149:in `require'
    from extconf.rb:4:in `<main>'
/Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require': cannot load such file -- nokogiri (LoadError)
    from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
    from extconf.rb:4:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in
/var/folders/h5/pv309pys7cd7_k058rl0wgx40000gn/T/bundler20210526-4419-9z2i9nnokogumbo-2.0.5/gems/nokogumbo-2.0.5 for inspection.
Results logged to
/var/folders/h5/pv309pys7cd7_k058rl0wgx40000gn/T/bundler20210526-4419-9z2i9nnokogumbo-2.0.5/extensions/universal-darwin-20/2.6.0/nokogumbo-2.0.5/gem_make.out

An error occurred while installing nokogumbo (2.0.5), and Bundler cannot continue.
Make sure that `gem install nokogumbo -v '2.0.5' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  html-proofer was resolved to 3.19.1, which depends on
    nokogumbo

另外,我也做了 gem install nokogumbo -v '2.0.5' --source 'https://rubygems.org/' 但是,它也没有用。

请帮我解决这个问题。非常感谢。

【问题讨论】:

【参考方案1】:

您可以通过在终端中运行xcode-select --install 来安装依赖项。

这是对类似问题How to install Xcode Command Line Tools的详细回答。

【讨论】:

xcode-select --install 如何解决我的问题?我天真地好奇。我得到错误的原因是什么?谢谢。 这是因为xcode-select --install 会在您的机器上安装某些依赖项。您尝试安装的 Gem 需要这些依赖项。我从事的许多项目都对 Gem Nokogiri 有某种依赖性,并且有一些系统依赖性,在此解释:nokogiri.org/…。 xcode-select --install 是获取它们的最快方式。 谢谢!!我明白了,我用你的 cmets 解决了它。【参考方案2】:

在安装 shopify-cli 之前尝试安装这些依赖项

sudo apt-get install build-essential

sudo apt-get install bison openssl curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev autoconf libc6-dev ncurses-dev automake libtool

【讨论】:

该问题要求为 Mac 提供解决方案。您的解决方案应该适用于 Ubuntu,但不适用于 MacOS。然后,您可以通过在终端中运行 xcode-select --install 来使用 Xcode。

以上是关于Gem:Ext::BuildError: ERROR: Failed to build gem native extension on Mac的主要内容,如果未能解决你的问题,请参考以下文章

Gem:Ext::BuildError: ERROR: Failed to build gem native extension on Mac

无法安装 RMagic gem

无法安装调试器

在linux中uuid4r gem安装出错

Rails 弹性 Beanstalk 无法部署 -

当我运行bundle install时,Nokogiri'无法构建gem native extension'