0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

nokogiri が macOS でインストールできない

Posted at

環境

  • macOS High Sierra 10.13.6
  • Ruby 2.3.8 (わけあって古い)

現象

macOS で nokogiri を bundle install すると、事前に brew install libxml2 しているにもかかわらず libxml2 が見つからないと言われて失敗します。

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
 
   current directory: 省略
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.
Using pkg-config gem version 1.1.9
checking for libxml-2.0... no
checking for libxslt... no
checking for libexslt... no
ERROR: cannot discover where libxml2 is located on your system. please make sure `pkg-config` is installed.
*** extconf.rb failed ***

対処

既知の対処法として、下記を事前に実行していましたが、うまくいきませんでした。いろいろググってみましたがわからず。

bundle config build.nokogiri --use-system-libraries

nokogiri 公式 を確認すると、以下を指定するようにとあり、そのとおりにしたらうまくいきました。

bundle config build.nokogiri --use-system-libraries \
  --with-xml2-include=$(brew --prefix libxml2)/include/libxml2

結論

公式は見よう。

0
2
0

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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?