title: How to fix "ERROR: Failed to build gem native extension." when installing eventmachine on macOS Mojave
body: <p>I am a novice with ruby and the command line.</p>
  
  <p><strong>Ruby -v:</strong> ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]</p>
  
  <p><strong>Mac:</strong> Mojave 10.14.2</p>
  
  <p>I am trying to open my Jekyll blog on my localhost, something which hasn't given me issues previously. However I ran</p>
  
  <pre><code>bundle exec jekyll serve
  </code></pre>
  
  <p>and get this error:</p>
  
  <pre><code>Could not find eventmachine-1.2.7 in any of the sources
  Run `bundle install` to install missing gems.
  </code></pre>
  
  <p>As suggested, I then run</p>
  
  <pre><code>bundle install
  </code></pre>
  
  <p>and get this error:</p>
  
  <pre><code>    Ignoring ffi-1.9.25 because its extensions are not built.  Try: gem pristine ffi --version 1.9.25
  Ignoring http_parser.rb-0.6.0 because its extensions are not built.  Try: gem pristine http_parser.rb --version 0.6.0
  Fetching gem metadata from https://rubygems.org/...........
  Using rake 10.5.0
  Using public_suffix 3.0.3
  Using addressable 2.5.2
  Using bundler 2.0.1
  Using colorator 1.1.0
  Using concurrent-ruby 1.0.5
  Fetching eventmachine 1.2.7
  Installing eventmachine 1.2.7 with native extensions
  Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
  
      current directory: /Users/name/Desktop/GitHub/blog/vendor/bundle/ruby/2.3.0/gems/eventmachine-1.2.7/ext
  /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20190212-57509-l19d0i.rb extconf.rb
  --with-cppflags=-I/usr/local/opt/openssl/include
  checking for main() in -lcrypto... *** 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)
      --with-ssl-dir
      --without-ssl-dir
      --with-ssl-include
      --without-ssl-include=${ssl-dir}/include
      --with-ssl-lib
      --without-ssl-lib=${ssl-dir}/lib
      --with-openssl-config
      --without-openssl-config
      --with-pkg-config
      --without-pkg-config
      --with-cryptolib
      --without-cryptolib
  /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:456:in `try_do': The compiler failed to
  generate an executable file. (RuntimeError)
  You have to install development tools first.
      from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:535:in `block in try_link0'
      from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/tmpdir.rb:89:in `mktmpdir'
      from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:532:in `try_link0'
      from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:556:in `try_link'
      from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:765:in `try_func'
      from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:997:in `block in have_library'
      from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:942:in `block in checking_for'
      from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:350:in `block (2 levels) in postpone'
      from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:320:in `open'
      from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:350:in `block in postpone'
      from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:320:in `open'
      from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:346:in `postpone'
      from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:941:in `checking_for'
      from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:992:in `have_library'
      from extconf.rb:8:in `block in check_libs'
      from extconf.rb:8:in `each'
      from extconf.rb:8:in `all?'
      from extconf.rb:8:in `check_libs'
      from extconf.rb:95:in `&lt;main&gt;'
  
  To see why this extension failed to compile, please check the mkmf.log which can be found here:
  
  /Users/name/Desktop/GitHub/blog/vendor/bundle/ruby/2.3.0/extensions/universal-darwin-18/2.3.0/eventmachine-1.2.7/mkmf.log
  
  extconf failed, exit code 1
  
  Gem files will remain installed in
  /Users/nbame/Desktop/GitHub/blog/vendor/bundle/ruby/2.3.0/gems/eventmachine-1.2.7 for inspection.
  Results logged to
  /Users/name/Desktop/GitHub/blog/vendor/bundle/ruby/2.3.0/extensions/universal-darwin-18/2.3.0/eventmachine-1.2.7/gem_make.out
  
  An error occurred while installing eventmachine (1.2.7), and Bundler cannot continue.
  Make sure that `gem install eventmachine -v '1.2.7' --source 'https://rubygems.org/'` succeeds before bundling.
  
  In Gemfile:
    jekyll was resolved to 3.8.3, which depends on
      em-websocket was resolved to 0.5.1, which depends on
        eventmachine
  </code></pre>
  
  <p>I have tried:</p>
  
  <ul>
  <li><p>Using <strong>gem install eventmachine -v '1.2.7' --source '<a href="https://rubygems.org/" rel="nofollow noreferrer">https://rubygems.org/</a>'</strong> which gives me the "ERROR: Failed to build gem native extension."</p></li>
  <li><p><strong>brew install coreutils</strong> as recommended <a href="https://stackoverflow.com/questions/37602947/bcrypt-ruby-3-1-2-gemextbuilderror-error-failed-to-build-gem-native-extens">here</a></p></li>
  <li><p>Every answer to <a href="https://stackoverflow.com/questions/30818391/gem-eventmachine-fatal-error-openssl-ssl-h-file-not-found">this question</a></p></li>
  <li><p>The answers <a href="https://stackoverflow.com/questions/52514791/after-upgrading-to-macos-mojave-gem-update-is-failing">here</a> relating to Mojave and gem update failing</p></li>
  <li><p><strong>gem pristine ffi --version 1.9.25</strong> because it suggested so in the error message</p></li>
  </ul>
  
  <p>My mkmf.log log is below</p>
  
  <pre><code>"xcrun clang -o conftest -I/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18 -I/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0 -I. -I/usr/local/opt/openssl/include  -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib -L.     -lruby.2.3.0  -lpthread -ldl -lobjc "
  In file included from conftest.c:1:
  In file included from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby.h:33:
  /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
  #include "ruby/config.h"
           ^~~~~~~~~~~~~~~
  1 error generated.
  checked program was:
  /* begin */
  1: #include "ruby.h"
  2: 
  3: int main(int argc, char **argv)
  4: {
  5:   return 0;
  6: }
  /* end */
  
  "pkg-config --exists openssl"
  package configuration for openssl is not found
  </code></pre>