LoginSignup
4
2

More than 3 years have passed since last update.

Vagrant+Railsでbindle install時にnokogiriインストールできないエラー

Last updated at Posted at 2019-10-19

内容

  • VagrantでRailsの環境構築中にbundle installしたとき、nokogiriがインストールできないエラーが発生したのでその対応
# エラーを発生させたコマンド
$ bundle install --path vendor/bundle
  • 結論;仮想環境とローカル環境の共有フォルダ上にパスを指定してgemをインストールしようとするとnokogiriがインストールできないとのことで、パスを指定して共有フォルダから外すとbundle installが通った

次のように共有ファイルを設定していた

Vagrantfile
config.vm.synced_folder "~/MyVagrant/sample_app", "/share"
# 解決
$ bundle install --path ~/hogehoge

環境

  • macOS Mojave 10.14.6
  • VirtualBox 6.0.10
  • Vagrant 2.2.5
  • centos/7 (virtualbox, 1905.1)
  • rbenv 1.1.2-4-g577f046
  • ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
  • Rails 6.0.0
  • Bundler version 2.0.2

エラー内容

bundle install時にnokogiriがインストールできないエラーが発生

# エラーを発生させたコマンド
$ bundle install --path vendor/bundle


# エラー内容
Fetching nokogiri 1.10.4
Installing nokogiri 1.10.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/share/sample_app/vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.4/ext/nokogiri
/home/vagrant/.rbenv/versions/2.6.5/bin/ruby -I
/home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0 -r
./siteconf20191019-20945-wvlcdn.rb extconf.rb
checking if the C compiler accepts ... *** 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.5/bin/$(RUBY_BASE_NAME)
    --help
    --clean
/home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:396:in `write': Bad
address @ io_writev - mkmf.log (Errno::EFAULT)
    from /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:396:in `puts'
    from /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:396:in `puts'
from /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:396:in `block
in xsystem'
    from /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:331:in `open'
from /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:395:in
`xsystem'
    from /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:474:in `try_do'
from /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:552:in
`try_link0'
from /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:570:in
`try_link'
from /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:460:in
`have_devel?'
    from /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:466:in `try_do'
from /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:585:in `block
in try_compile'
from /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:532:in
`with_werror'
from /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:585:in
`try_compile'
    from extconf.rb:138:in `nokogiri_try_compile'
    from extconf.rb:162:in `block in add_cflags'
from /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/2.6.0/mkmf.rb:643:in
`with_cflags'
    from extconf.rb:161:in `add_cflags'
    from extconf.rb:416:in `<main>'

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

/share/sample_app/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0-static/nokogiri-1.10.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/share/sample_app/vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.4 for inspection.
Results logged to
/share/sample_app/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0-static/nokogiri-1.10.4/gem_make.out

An error occurred while installing nokogiri (1.10.4), and Bundler
cannot continue.
Make sure that `gem install nokogiri -v '1.10.4' --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

やったこと

nokogiriインストールの方法で熱心に解決策を探していましたが、公式サイト通りに進めてgem install nokogiriをして、再度bundle installしても解決せず
その他、色々インストール、アップデートしてみてうまくいかなかった

解決

こちらの記事で解決。
仮想環境とローカル環境の共有フォルダ上にgemをインストールしようとすると怒られるとのこと

今回一番初めにVagrantfileで次のように、共有ファイルを設定していたためnokogiriに怒られた模様

Vagrantfile
config.vm.synced_folder "~/MyVagrant/sample_app", "/share"

そこで、bundle installでパスを共有ファイル外に指定すると解決

$ bundle install --path ~/hogehoge

共有ファイルの設定をコネコネしても解決できると思いますが試してません。

4
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2