質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Q&A

1回答

2980閲覧

bundle installにおいてnokogiri1.8.5がインストールされず終了してしまう

jaguarundi

総合スコア19

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

0グッド

1クリップ

投稿2019/08/05 12:52

前提・実現したいこと

railsでWebアプリ開発に取り組もうとしている初心者です。
職場でまず環境構築に取り組んだのですが、
・rubyおよびrbenvといった基本的な部分は正常にインストール、バージョンも最新
・仕事とは別の自分のrails環境にはnokogiriが正常に入っている
・gemを使ってnokogiriをインストールすると正常に入る

上記のような状況にも関わらず、Gemfileなるものでbundle install --path vendor/bundleを実行したところ、以下のQiitaの記事のような症状でbundleが正常に終了せず、結局環境構築を終了させることができませんでした。
https://qiita.com/yuki_uchida/items/3089d4e6bc9c8113c581

なので、どうにかこのエラーを解消して職場での開発にきちんと従事できるようになりたいです。

発生している問題・エラーメッセージ

Using rake 12.3.2 Using concurrent-ruby 1.1.5 Using aasm 5.0.1 Using abstract_type 0.0.7 Using i18n 1.6.0 Using minitest 5.11.3 Using thread_safe 0.3.6 Using tzinfo 1.2.5 Using activesupport 5.2.2.1 Using builder 3.2.3 Using erubi 1.8.0 Using mini_portile2 2.3.0 Fetching nokogiri 1.8.5 Installing nokogiri 1.8.5 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /Users/johndoe/Desktop/xxxxx/vendor/bundle/ruby/2.6.0/gems/nokogiri-1.8.5/ext/nokogiri /Users/johndoe/.rbenv/versions/2.6.3/bin/ruby -I /Users/johndoe/.rbenv/versions/2.6.3/lib/ruby/site_ruby/2.6.0 -r ./siteconf20190805-942-1h1v7xa.rb extconf.rb --use-system-libraries checking if the C compiler accepts ... yes checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no Building nokogiri using system libraries. 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=/Users/johndoe/.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 To see why this extension failed to compile, please check the mkmf.log which can be found here: /Users/johndoe/Desktop/xxxxx/vendor/bundle/ruby/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/nokogiri-1.8.5/mkmf.log Permission denied @ rb_file_s_rename - (mkmf.log, /Users/johndoe/Desktop/xxxxx/vendor/bundle/ruby/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/nokogiri-1.8.5/mkmf.log) Gem files will remain installed in /Users/johndoe/Desktop/xxxxx/vendor/bundle/ruby/2.6.0/gems/nokogiri-1.8.5 for inspection. Results logged to /Users/johndoe/Desktop/xxxxx/vendor/bundle/ruby/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/nokogiri-1.8.5/gem_make.out An error occurred while installing nokogiri (1.8.5), and Bundler cannot continue. **__Make sure that `gem install nokogiri -v '1.8.5' --source 'https://rubygems.org/'`__** succeeds before bundling. In Gemfile: activeadmin_addons was resolved to 1.7.0, which depends on xdan-datetimepicker-rails was resolved to 2.5.4, which depends on rails was resolved to 5.2.2.1, which depends on actioncable was resolved to 5.2.2.1, which depends on actionpack was resolved to 5.2.2.1, which depends on actionview was resolved to 5.2.2.1, which depends on rails-dom-testing was resolved to 2.0.3, which depends on nokogiri

試したこと

https://qiita.com/ganta/items/3bb378726149a759d085
同様の症状の記事を参考に、

・brew install libxml2をしたのちにbundle config build.nokogiri --use-system-libraries --with-xml2-include=$(brew --prefix libxml2)/include/libxml2を実行

・bundle config build.nokogiri --use-system-librariesを実行したのちにbundle install

https://qiita.com/nipe0324/items/b12668806ab6be890208
同じ症状で別の解決策である↓を実行

・brew tap homebrew/dupes
brew install libxml2 libxslt libiconv
brew link libxml2 --force
brew link libxslt --force
gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"

いずれも正しく動作しますが、いざbundle installを行うと上記のエラーが出てnokogiriのインストールに失敗してしまい、自分では手におえない状況です。

エラー中のgem install nokogiri -v '1.8.5' --source 'https://rubygems.org/'
も何度も試しましたが、

ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension. current directory: /Users/xxxxx/.rbenv/gems/2.6.0/gems/nokogiri-1.8.5/ext/nokogiri /Users/xxxxx/.rbenv/versions/2.6.3/bin/ruby -I /Users/xxxxx/.rbenv/versions/2.6.3/lib/ruby/site_ruby/2.6.0 -r ./siteconf20190805-3672-jo1shz.rb extconf.rb checking if the C compiler accepts ... yes checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no Building nokogiri using packaged libraries. Using mini_portile version 2.3.0 checking for iconv.h... yes checking for gzdopen() in -lz... yes checking for iconv... yes ************************************************************************ IMPORTANT NOTICE: Building Nokogiri with a packaged version of libxml2-2.9.8 with the following patches applied: - 0001-Revert-Do-not-URI-escape-in-server-side-includes.patch - 0002-Fix-nullptr-deref-with-XPath-logic-ops.patch - 0003-Fix-infinite-loop-in-LZMA-decompression.patch Team Nokogiri will keep on doing their best to provide security updates in a timely manner, but if this is a concern for you and want to use the system library instead; abort this installation process and reinstall nokogiri as follows: gem install nokogiri -- --use-system-libraries [--with-xml2-config=/path/to/xml2-config] [--with-xslt-config=/path/to/xslt-config] If you are using Bundler, tell it to use the option: bundle config build.nokogiri --use-system-libraries bundle install Note, however, that nokogiri is not fully compatible with arbitrary versions of libxml2 provided by OS/package vendors. (略) To see why this extension failed to compile, please check the mkmf.log which can be found here: /Users/xxxxx/.rbenv/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/nokogiri-1.8.5/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /Users/xxxxx/.rbenv/gems/2.6.0/gems/nokogiri-1.8.5 for inspection. Results logged to /Users/xxxxx/.rbenv/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/nokogiri-1.8.5/gem_make.out

と表示され、支持された通りmkmf.logをみてみたのですが、素人の私には皆目見当がつかない次第です。

補足情報(FW/ツールのバージョンなど)

ProductName: Mac OS X
ProductVersion: 10.14.6

なお、Xcodeがないと正しく動作しないという声もあったので導入し、command line toolsを正しく設定しましたが、状況は変わりませんでした。

以下rubyのバージョンなど参考になりそうなもの
$ which nokogiri
/Users/xxxxx/.rbenv/shims/nokogiri
(どのディレクトリで実行しても同じ表示)

$ ruby -version
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
Traceback (most recent call last):
-e:1:in <main>': undefined local variable or method rsion' for main:Object (NameError)

$ bundle -v
Bundler version 1.17.3

$ rails -v
Rails 5.2.3
(git cloneしたプロジェクト内でrails -vを実行すると
Could not find nokogiri-1.8.5 in any of the sources
Run bundle install to install missing gems.
でrailsのバージョンは確認できません。)

なおlibxml2はwhichコマンドでは確認できませんでしたが、brew listでは確認できます。

環境構築で躓いたので、今の所1人だけDockerを用いて開発している状況です。
どうにかして他の人と一緒の環境で開発したいと切実に願っているので、お力を貸してください!

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

nokogiriがビルドできないってよくあることなので、検索すると情報がたくさん見つかります。

下記などどうでしょうか?

https://qiita.com/tdkn/items/88a2ba7631e118483163

投稿2019/08/05 14:54

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

jaguarundi

2019/08/06 00:57

回答ありがとうございます。 今回はbundleの問題ということで、qiitaの記事の通りに brew link --force libxml2 libxslt libiconv を行ったところ、シンボリックリンクがcreatedにならず、libxml2、libxslt、libiconvそれぞれに Warning: Refusing to link macOS-provided software: libxml2 If you need to have libxml2 first in your PATH run: echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.bash_profile For compilers to find libxml2 you may need to set: export LDFLAGS="-L/usr/local/opt/libxml2/lib" export CPPFLAGS="-I/usr/local/opt/libxml2/include" For pkg-config to find libxml2 you may need to set: という表示が出ました。 エラーに載っているexportとechoは実行して、最後に載っている gem install nokogiri -- --use-system-libraries\ --with-iconv-dir="$(brew --prefix libiconv)"\ --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config"\ --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config" を実行したものの、やはり結果は変わりませんでした。 しかし、おそらくシンボリックリンクの作成ができていないことによるエラーなのではないかと思います。 エラーログの手順通りに実行しても反映されないのが不思議ですが、、、
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問