title: Build Gem Native Extension
body: <blockquote>
    <p>Passing on knowledge I just learned in the hopes of reducing the
    headache others may experience with native gem extensions like I've
    had.</p>
    
    <p><strong>TL;DR</strong> - Had an issue with <code>bundle install</code>. Read <strong>mkmf.log</strong> as mentioned in the error. The log had another error that I googled. Installed
    necessary library. Afterwards, <code>bundle install</code> was successful.</p>
  </blockquote>
  
  <p>Trying to install gems using <code>bundler</code> and getting errors about building gem native extensions:</p>
  
  <pre><code>$ bundle install
  Fetching gem metadata from https://rubygems.org/...........
  Fetching version metadata from https://rubygems.org/..
  Resolving dependencies...
  Installing daemons 1.2.3
  Installing eventmachine 1.0.8 with native extensions
  
  Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
  
      current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/eventmachine-1.0.8/ext
  /usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160309-8483-1so3k75.rb extconf.rb
  *** 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.
  
  &lt;...&gt;
  
  To see why this extension failed to compile, please check the mkmf.log which can be found here:
  
    /usr/local/rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/eventmachine-1.0.8/mkmf.log
  
  extconf failed, exit code 1
  
  &lt;...&gt;
  Installing mysql2 0.4.3 with native extensions
  
  Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
  
      current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/mysql2-0.4.3/ext/mysql2
  /usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160309-8483-1oxfnj5.rb extconf.rb
  checking for ruby/thread.h... *** 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.
  
  &lt;...&gt;
  
  To see why this extension failed to compile, please check the mkmf.log which can be found here:
  
    /usr/local/rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/mysql2-0.4.3/mkmf.log
  
  extconf failed, exit code 1
  
  &lt;...&gt;
  Installing rack 1.6.4
  Installing tilt 2.0.1
  Using bundler 1.11.2
  An error occurred while installing eventmachine (1.0.8), and Bundler cannot continue.
  Make sure that `gem install eventmachine -v '1.0.8'` succeeds before bundling.
  </code></pre>