Posted at

Mac OS Catalina にアップグレードしたら bundle install でコケる

Mac OS Catalina へアップグレード後に、Gemfile で Rails のみを指定して bundle install したらコケたので備忘です。


エラー内容

$ bundle install --path vendor/bundle

Fetching gem metadata from https://rubygems.org/.............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Fetching rake 13.0.0
Installing rake 13.0.0
Fetching concurrent-ruby 1.1.5
Installing concurrent-ruby 1.1.5
Fetching i18n 1.7.0
Installing i18n 1.7.0
Fetching minitest 5.12.2
Installing minitest 5.12.2
Fetching thread_safe 0.3.6
Installing thread_safe 0.3.6
Fetching tzinfo 1.2.5
Installing tzinfo 1.2.5
Fetching zeitwerk 2.2.0
Installing zeitwerk 2.2.0
Fetching activesupport 6.0.0
Installing activesupport 6.0.0
Fetching builder 3.2.3
Installing builder 3.2.3
Fetching erubi 1.9.0
Installing erubi 1.9.0
Fetching mini_portile2 2.4.0
Installing mini_portile2 2.4.0
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:
./vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.4/ext/nokogiri
~/.rbenv/versions/2.6.3/bin/ruby -I
~/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r
./siteconf20191011-4979-1ke4qzu.rb extconf.rb
checking if the C compiler accepts -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2... ***
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=~/.rbenv/versions/2.6.3/bin/$(RUBY_BASE_NAME)
--help
--clean
~/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an
executable file. (RuntimeError)
You have to install development tools first.
from ~/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
from ~/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:532:in `with_werror'
from ~/.rbenv/versions/2.6.3/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 ~/.rbenv/versions/2.6.3/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:

./vendor/bundle/ruby/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/nokogiri-1.10.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
./vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.4 for inspection.
Results logged to
./vendor/bundle/ruby/2.6.0/extensions/x86_64-darwin-18/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 6.0.0, which depends on
actioncable was resolved to 6.0.0, which depends on
actionpack was resolved to 6.0.0, which depends on
actionview was resolved to 6.0.0, which depends on
rails-dom-testing was resolved to 2.0.3, which depends on
nokogiri

$ gem install nokogiri -v '1.10.4' --source 'https://rubygems.org/'
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.

current directory: ~/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.4/ext/nokogiri
~/.rbenv/versions/2.6.3/bin/ruby -I ~/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r ./siteconf20191011-5067-7lnwuv.rb extconf.rb
checking if the C compiler accepts -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2... *** 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=~/.rbenv/versions/2.6.3/bin/$(RUBY_BASE_NAME)
--help
--clean
~/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from ~/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
from ~/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:532:in `with_werror'
from ~/.rbenv/versions/2.6.3/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 ~/.rbenv/versions/2.6.3/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:

~/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/nokogiri-1.10.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in ~/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.4 for inspection.
Results logged to ~/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/nokogiri-1.10.4/gem_make.out


解決策

$ xcode-select --install

でビルドできるようになりました。

参考

MacOS SierraでSassがインストール出来ない時の解決策