2

Just updated to macOS Mojave, reinstalled mysql via brew & downloaded latest xcode 9.2 . While triying to setup a development enviroment for an old rails project, bundle crashes on installation of mysql2 gem. In the beggining i thought it was because latest mysql2 version, is not compatible with ruby 1.9 so i tried:

gem install mysql2 -v '0.3.17'

and i received:

/Users/me/.rvm/rubies/ruby-1.9.3-p125/bin/ruby 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.

Provided configuration options: --with-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=/Users/me/.rvm/rubies/ruby-1.9.3-p125/bin/ruby /Users/me/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:381:in try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /Users/me/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:506:intry_cpp' from /Users/me/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:931:in block in have_header' from /Users/me/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:790:inblock in checking_for' from /Users/me/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:284:in block (2 levels) in postpone' from /Users/me/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:254:inopen' from /Users/me/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:284:in block in postpone' from /Users/me/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:254:inopen' from /Users/me/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:280:in postpone' from /Users/me/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:789:inchecking_for' from /Users/me/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:930:in have_header' from extconf.rb:9:in'

copy from /Users/me/.rvm/gems/ruby-1.9.3-p125@mailcatcher/gems/mysql2-0.2.18/ext/mysql2/mkmf.log:

"/usr/bin/gcc-4.2 -o conftest -I/Users/me/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/x86_64-darwin10.8.0 -I/Users/me/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/backward -I/Users/me/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1 -I. -I/Users/me/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -fno-common -pipe conftest.c -L. -L/Users/me/.rvm/rubies/ruby-1.9.3-p125/lib -L/Users/me/.rvm/usr/lib -L. -L/usr/local/lib -lruby.1.9.1 -lpthread -ldl -lobjc " checked program was: /* begin / 1: #include "ruby.h" 2: 3: int main() {return 0;} / end */

HaCos
  • 165
  • 1
  • 3
  • 14

2 Answers2

3

It sounds like you're either missing the XCode command line tools: xcode-select --install

Or mySQL packages: If you don't already have homebrew: $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" Then to install mysql: brew install mysql

I can't remember which solved this issue for me in the past but I'm sure it was one of them.

James Balazs
  • 88
  • 1
  • 4
  • mysql has been installed with success via homebrew but still the gem mysql2 returns the error i mentioned above. – HaCos Nov 09 '18 at 06:35
  • @HaCos that could be because Ruby needs the header files (found in the development toolkit) to install the gem. Homebrew can install mysql without those header files. Definitely should run the `xcode-select install` command if you haven't already – Jay Dorsey Nov 18 '18 at 00:21
  • @JayDorsey mysql is already installed with success via homebrew. – HaCos Nov 19 '18 at 07:20
  • After, `xcode-select --install`, open Xcode, and install "Additional Components", restart computer, open `/Library/Developer/CommandLineTools/Packages` and there will be a file `macOS_SDK_headers_for_macOS_10.14.pkg`. Open that. – Jared Beck Jan 01 '19 at 23:52
0

Cross linking my answer to almost this exact same question. I think it might just be not finding the correct config path

sudo gem install mysql2 -- --with-mysql-config=/usr/local/bin/mysql_config

See the answer here

edit: formatting

awsmsce
  • 187
  • 9
  • It returns: ERROR: Error installing mysql2: mysql2 requires Ruby version >= 2.0.0. – HaCos Nov 09 '18 at 07:24
  • sounds like you either need to downgrade the gem to a version that supports < ruby 2.0, or upgrade to ruby 2.0. Personally I'm using 2.4.4 on my current project. – awsmsce Nov 09 '18 at 18:16
  • I try gem install mysql2 -v '0.3.17' --source 'http://rubygems.org/' but i receive: Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. /Users/me/.rvm/rubies/ruby-1.9.3-p125/bin/ruby 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. I updated my initial post with mkmf.log content. – HaCos Nov 12 '18 at 11:47