LoginSignup
2
0

More than 3 years have passed since last update.

macOS Mojave で libxml-ruby のインストールに失敗するときは Command Line Tools for Xcode を入れてみる

Last updated at Posted at 2019-08-15

問題点

macOS Mojave (10.14) で Rails の bundle install などの際、下記のエラーが出て止まることがあります。

An error occurred while installing libxml-ruby (3.1.0), and Bundler cannot continue.
Make sure that `gem install libxml-ruby -v '3.1.0' --source 'https://rubygems.org/'` succeeds before bundling.

エラーメッセージを少し遡って読むと、次のような行が見つかる場合の対処法です。

checking for libxml/xmlversion.h in
/opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no
*** 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.

解決策

libxml2 が見つからない、と言われています。

これは /usr/include にあることが期待されるヘッダーファイルが存在しないことによるもので、Xcode の SDK ファイルをインストールすればよいのです。環境によっては /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg というファイルが既に存在する場合もあるそうなので、まずそれがあるか確認してみてください。

私の場合は見つかりませんでした。この場合、Appleのデベロッパサイト https://developer.apple.com/download/more/ に行ってログインし、(もしデベロッパアカウントを持ってない場合はここで規約に同意して作成し、) Command Line Tools (macOS 10.14) for Xcode 10.x を探してダウンロード/インストールしましょう(ただし 10.x はあなたのマシンの Xcode のバージョン)。すると先ほどのディレクトリ /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg というファイルができています。

macOS_SDK_headers_for_macOS_10.14.pkg をダブルクリックしてインストールしましょう。

これで例えば

$ gem install libxml-ruby -v '3.1.0' --source 'https://rubygems.org/'`

としてみて(バージョンはインストールしたいバージョンに合わせてください)、成功するかどうか確認してみてください。

参考

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