An error occurred while installing nokogiri (1.10.5), and Bundler cannot continue. Make sure that gem install nokogiri -v '1.10.5' --source 'https://rubygems.org/' succeeds before bundling.
のエラーでbundle installがNokogiriからインストールできない
背景
$ bundle install
したらNokogiriでエラー(ターミナル)
vagrant@ubuntu-xenial:~/workspace/rails_base_exam/insta_exam$ bundle
Fetching https://github.com/stympy/faker.git
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies.....
Using rake 13.0.1
Using concurrent-ruby 1.1.5
Using i18n 1.7.0
Using minitest 5.13.0
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.2.3
Using builder 3.2.3
Using erubi 1.9.0
Using mini_portile2 2.4.0
Fetching nokogiri 1.10.5
Installing nokogiri 1.10.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory:
/home/vagrant/workspace/rails_base_exam/insta_exam/vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.5/ext/nokogiri
/home/vagrant/.rbenv/versions/2.6.3/bin/ruby -I
/home/vagrant/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r
./siteconf20191113-32364-ve2pbr.rb extconf.rb --use-system-libraries
checking if the C compiler accepts ... yes
Building nokogiri using system libraries.
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"
checking for xmlParseDoc() in libxml/parser.h... yes
checking for xsltParseStylesheetDoc() in libxslt/xslt.h... no
checking for xsltParseStylesheetDoc() in -lxslt... no
checking for xsltParseStylesheetDoc() in -llibxslt... no
-----
libxslt is missing. Please locate mkmf.log to investigate how it is failing.
-----
*** 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/vagrant/.rbenv/versions/2.6.3/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
--with-xsltlib
--without-xsltlib
--with-libxsltlib
--without-libxsltlib
To see why this extension failed to compile, please check the mkmf.log which can be
found here:
/home/vagrant/workspace/rails_base_exam/insta_exam/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0-static/nokogiri-1.10.5/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in
/home/vagrant/workspace/rails_base_exam/insta_exam/vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.5
for inspection.
Results logged to
/home/vagrant/workspace/rails_base_exam/insta_exam/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0-static/nokogiri-1.10.5/gem_make.out
An error occurred while installing nokogiri (1.10.5), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.10.5' --source 'https://rubygems.org/'`
succeeds before bundling.
In Gemfile:
rails was resolved to 5.2.3, which depends on
actioncable was resolved to 5.2.3, which depends on
actionpack was resolved to 5.2.3, which depends on
actionview was resolved to 5.2.3, which depends on
rails-dom-testing was resolved to 2.0.3, which depends on
nokogiri
解決コマンド
windows
$ sudo apt-get install libxml2-dev #libxml2-devのインストール
$ sudo apt-get install libxslt1-dev #libxslt1-devのインストール
$ sudo apt-get install libxslt-dev #libxslt-devのインストール
$ sudo apt-get install ruby-dev #ruby-devのインストール
$ bundle config build.nokogiri --use-system-libraries #libmxl2を利用するように設定
$ gem install nokogiri -v '1.10.5' --source 'https://rubygems.org/'
$ bundle install --path vendor/bundle
mac
$ brew tap homebrew/dupes
$ brew install libxml2 libxslt libiconv
$ brew link --force libxml2 ##--force--オプションを付けてインストール
$ brew link --force libxslt ##--force--オプションを付けてインストール
$ bundle config build.nokogiri --use-system-libraries #libmxl2を利用するように設定
$ bundle install --path vendor/bundle
https://qiita.com/E-46/items/b1dc5807f8604952bf93
https://blog.vtryo.me/entry/error-install-nokogiri
https://qiita.com/thunders/items/101c6b329830fb1fb27d