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

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

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

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

Q&A

解決済

2回答

2997閲覧

Rails nokogiriで正常にbundle installできない

ruby_0ct

総合スコア57

Ruby on Rails

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

0グッド

0クリップ

投稿2018/04/21 18:41

編集2018/04/22 17:05

bundle installを実行するとnokogiriのlibxml2に関するエラーが発生してしまいます。

Fetching nokogiri 1.8.1 Installing nokogiri 1.8.1 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /Users/macbookpro/Documents/Ruby/members/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.8.1/ext/nokogiri /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20180423-89744-d6nawv.rb extconf.rb --use-system-libraries --with-iconv-dir=/usr/local/opt/libiconv 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. 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=/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/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/macbookpro/Documents/Ruby/members/vendor/bundle/ruby/2.3.0/extensions/universal-darwin-17/2.3.0/nokogiri-1.8.1/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /Users/macbookpro/Documents/Ruby/members/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.8.1 for inspection. Results logged to /Users/macbookpro/Documents/Ruby/members/vendor/bundle/ruby/2.3.0/extensions/universal-darwin-17/2.3.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'` succeeds before bundling. In Gemfile: rails was resolved to 5.0.6, which depends on actioncable was resolved to 5.0.6, which depends on actionpack was resolved to 5.0.6, which depends on actionview was resolved to 5.0.6, which depends on rails-dom-testing was resolved to 2.0.3, which depends on nokogiri

以下のQiitaを参考にすると
Qiita - OSX への nokogiri 1.6.8.rc3 の install でハマって解決したメモ
libxml2のリンクがされてないことが原因のようですが、実際に見てみると

$ ls -la /usr/local/lib/ | grep libxml2 lrwxr-xr-x 1 macbookpro admin 43 4 22 02:46 libxml2.2.dylib -> ../Cellar/libxml2/2.9.7/lib/libxml2.2.dylib lrwxr-xr-x 1 macbookpro admin 37 4 22 02:46 libxml2.a -> ../Cellar/libxml2/2.9.7/lib/libxml2.a lrwxr-xr-x 1 macbookpro admin 41 4 22 02:46 libxml2.dylib -> ../Cellar/libxml2/2.9.7/lib/libxml2.dylib lrwxr-xr-x 1 macbookpro admin 39 4 22 02:46 xml2Conf.sh -> ../Cellar/libxml2/2.9.7/lib/xml2Conf.sh

すでにリンクがされています。

エラー文を検索しながらサイトに書いてあることを一通りやってみたのですがうまくいかず...

再度bundle installをやって見ても同じエラーになってしまいます。どうすれば、正常に行われるでしょうか?
解決策をご教授いただけると助かります。

#行ったこと

$ bundle config build.nokogiri --use-system-libraries You are replacing the current global value of build.nokogiri, which is currently "--use-system-libraries --with-iconv-dir=/usr/local/opt/libiconv"

xcodeのコマンドラインツールのインストール

$ xcode-select --install xcode-select: error: command line tools are already installed, use "Software Update" to install updates

リンクし直しても当然、すでにされていると言われる。
「brewにいくつかインストールが必要だ」と書いてあっても、下記の環境の通り、全て揃っている。

環境

macOS High Sierra
gemにはすでに以下がインストール済みです。

nokogiri (1.5.6) pkg-config (1.3.0)

homebrewには

libiconv libxslt pkg-config libxml2

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

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

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

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

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

guest

回答2

0

自己解決

解決をいたしました!

投稿2018/04/28 19:02

ruby_0ct

総合スコア57

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

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

0

投稿2018/04/21 19:55

hichon

総合スコア5737

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

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

ruby_0ct

2018/04/22 06:19

ご回答ありがとうございます。 gemにはpkg-config (1.3.0)とnokogiri (1.5.6)がインストールされています。 homebrewにもpkg-configがインストールされているのですが、パスの問題でしょうか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問