ruby-on-rails - Nokogiri gem build error failed to build gem native extension on WSL with RVM

标签 ruby-on-rails ruby ubuntu nokogiri windows-subsystem-for-linux

我将 WSL (ubuntu) 用于带有 RVM 版本 1.29.12 的 Windows 10。
Ruby 版本是 2.4.1p11。捆绑器版本 1.16.4。
当我执行捆绑安装时,它在 nokogiri 上停止并抛出此错误:

Fetching gem metadata from https://rubygems.org/............
Using rake 12.3.0
Using concurrent-ruby 1.0.5
Using i18n 0.9.1
Using minitest 5.10.3
Using thread_safe 0.3.6
Using tzinfo 1.2.4
Using activesupport 5.1.4
Using builder 3.2.3
Using erubi 1.7.0
Using mini_portile2 2.3.0
Fetching nokogiri 1.8.1
Installing nokogiri 1.8.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

checking if the C compiler accepts ... no
Building nokogiri using system libraries.
pkg-config could not be used to find libxml-2.0
Please install either `pkg-config` or the pkg-config gem per

    gem install pkg-config -v "~> 1.1"

pkg-config could not be used to find libxslt
Please install either `pkg-config` or the pkg-config gem per

    gem install pkg-config -v "~> 1.1"

pkg-config could not be used to find libexslt
Please install either `pkg-config` or the pkg-config gem per

    gem install pkg-config -v "~> 1.1"

ERROR: cannot discover where libxml2 is located on your system. please make sure `pkg-config` is installed.
*** 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=/home/mike/.rvm/rubies/ruby-2.4.1/bin/$(RUBY_BASE_NAME)
        --help
        --clean
        --use-system-libraries
        --with-zlib-dir
        --without-zlib-dir
        --with-zlib-include
        --without-zlib-include=${zlib-dir}/include
        --with-zlib-lib
        --without-zlib-lib=${zlib-dir}/lib
        --with-xml2-dir
        --without-xml2-dir
        --with-xml2-include
        --without-xml2-include=${xml2-dir}/include
        --with-xml2-lib
        --without-xml2-lib=${xml2-dir}/lib
        --with-libxml-2.0-config
        --without-libxml-2.0-config
        --with-pkg-config
        --without-pkg-config
        --with-xslt-dir
        --without-xslt-dir
        --with-xslt-include
        --without-xslt-include=${xslt-dir}/include
        --with-xslt-lib
        --without-xslt-lib=${xslt-dir}/lib
        --with-libxslt-config
        --without-libxslt-config
        --with-exslt-dir
        --without-exslt-dir
        --with-exslt-include
        --without-exslt-include=${exslt-dir}/include
        --with-exslt-lib
        --without-exslt-lib=${exslt-dir}/lib
        --with-libexslt-config
        --without-libexslt-config

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

  /mnt/c/Users/test/vendor/bundle/ruby/2.4.0/extensions/x86_64-linux/2.4.0/nokogiri-1.8.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /mnt/c/Users/test/vendor/bundle/ruby/2.4.0/gems/nokogiri-1.8.1 for inspection.
Results logged to /mnt/c/Users/test/vendor/bundle/ruby/2.4.0/extensions/x86_64-linux/2.4.0/nokogiri-1.8.1/gem_make.out

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

In Gemfile:
  view_source_map was resolved to 0.1.4, which depends on
    rails was resolved to 5.1.4, which depends on
      actioncable was resolved to 5.1.4, which depends on
        actionpack was resolved to 5.1.4, which depends on
          actionview was resolved to 5.1.4, which depends on
            rails-dom-testing was resolved to 2.0.3, which depends on
              nokogiri
我尝试了一些我在网上找到的建议
    gem install pkg-config -v "~> 1.1"
或者
sudo apt-get install libxml2-dev libxslt-dev
但我似乎无法摆脱错误。
我也尝试单独安装 nokogiri 然后再次执行 bundle install 但同样的问题仍然存在。
提前致谢。

最佳答案

尝试这个。这是指示捆绑器寻找库

bundle config build.nokogiri --use-system-libraries
bundle install
如果以上不起作用。检查您的日志文件。在大多数情况下,一些库会丢失。
sudo apt-get install zlib1g-dev
sudo apt-get install libxml2-dev
sudo apt-get install libxslt-dev

关于ruby-on-rails - Nokogiri gem build error failed to build gem native extension on WSL with RVM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67620469/

相关文章:

mongodb - Ansible-Playbook 无法安装 MongoDB

python - 在 Ubuntu 上将 Pyqt 安装到替代 Python 版本

ruby-on-rails - 以不同用户身份运行 capistrano 任务

ruby-on-rails - 用户属性不会保存

ruby-on-rails - 如何忽略 Zeitwerk for Rails 6 中的文件夹?

javascript - @user = 选择了什么

ruby-on-rails - 将选项哈希传递给 sidekiq 工作器

ruby-on-rails - 你如何说服你的经理你的项目需要大量重构?

ruby - 无法理解如何索引数组项

android - Ubuntu 16.04 上的 aarch64-linux-android-gcc 错误 "poll.h"未找到