6

I'm new with RoR and I'm trying to install Mysql2 -v '0.3.11'. I have OS X Mountain Lion, rails 3.2.6 ,ruby 1.9.3.

Below is the error I get. I looked everywhere and didn't find anything.

$gem install mysql2 -v '0.3.11'
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
ERROR: Failed to build gem native extension.

    /Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile

make
compiling client.c
In file included from client.c:1:
In file included from ./mysql2_ext.h:8:
In file included from /Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby.h:32:
/Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/ruby.h:105:37:     error: 'ruby_check_sizeof_long' declared as an array with a negative size
typedef char ruby_check_sizeof_long[SIZEOF_LONG == sizeof(long) ? 1 : -1];
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/x86_64-darwin12.0.0/ruby/config.h:24:21: note: expanded from macro 'SIZEOF_LONG'
#define SIZEOF_LONG 8
                ^
In file included from client.c:1:
In file included from ./mysql2_ext.h:8:
In file included from /Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby.h:32:
/Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/ruby.h:109:38: error: 'ruby_check_sizeof_voidp' declared as an array with a negative size
typedef char ruby_check_sizeof_voidp[SIZEOF_VOIDP == sizeof(void*) ? 1 : -1];
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/x86_64-darwin12.0.0/ruby/config.h:28:22: note: expanded from macro 'SIZEOF_VOIDP'
#define SIZEOF_VOIDP 8
                 ^
In file included from client.c:1:
In file included from ./mysql2_ext.h:8:
In file included from /Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby.h:32:
In file included from /Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/ruby.h:1377:
In file included from /Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/intern.h:34:
/Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/st.h:67:45: error: 'st_check_for_sizeof_st_index_t' declared as an array with a negative size
typedef char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP == (int)sizeof(st_index_t) ? 1 : -1];
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/curiosity/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/x86_64-darwin12.0.0/ruby/config.h:28:22: note: expanded from macro 'SIZEOF_VOIDP'
#define SIZEOF_VOIDP 8
                 ^
3 errors generated.
make: *** [client.o] Error 1


Gem files will remain installed in /Users/curiosity/.rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/curiosity/.rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.11/ext/mysql2/gem_make.out

Thanks for your help.

yabenjo
  • 61
  • 1
  • 2

3 Answers3

27

You're using RVM instead of the Ruby that comes with 10.8. Good. Now, stop using the MySQL that comes with 10.8.

Install and update Homebrew. Now run

brew install mysql

Use the /Gemfile in your project to install the mysql2 gem. Add

gem "mysql2"

to your /Gemfile. Then update your application with Bundler by running

bundle install

Let the package managers (Homebrew and Bundler) work for you.

This should fix the issues you're having.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
deefour
  • 34,974
  • 7
  • 97
  • 90
  • If you're going to down-vote, please explain why so my answer can be improved. – deefour Oct 10 '12 at 16:14
  • The command brew install worked, however, rvm exec bundle install did not. Thanks anyway :) – Francisco Quintero Apr 11 '13 at 15:15
  • @Francisco does running `bundle install` directly work for you? I haven't used rvm in a long time, it seems the `rvm exec` or `rvm do` are no longer present. Feel free to post a more appropriate edit to the question with what *did* work for you. – deefour Apr 11 '13 at 17:25
  • Sure. The command `brew install mysql` worked, and so did `bundle install`. With these steps I could successfully install mysql2 – Francisco Quintero Apr 12 '13 at 18:00
0

As Deefour said, I had to use RVM. Answer goes to him, I just couldn't comment on his answer. +1

But rvm exec bundle install gave me an error:

rvm do bundle install was removed, use rvm 1.9.2,1.9.3 do bundle install or rvm all do bundle install instead.

I used sudo rvm all do bundle install and it all went flawlessly from then on.

Community
  • 1
  • 1
0

I too get same type of error in mac10.10 and used below commands that work for me:

  1. Install and upgrade Homebrew using:

    brew install mysql

  2. run Install Mysql gem file using:

    gem install mysql2 -v '0.3.11'

  3. Run bundle install

codingEnthusiast
  • 3,800
  • 2
  • 25
  • 37