views:

2572

answers:

5

Hi guys,

I am having some problems when trying to install mysql2 gem for Rails 3. When I try to install it by issuing "bundle install" command or "gem install mysql2" it gives me following error "Error installing mysql2: ERROR: Failed to build gem native extension." Did anyone have any luck with this?

Thanks!

+1  A: 

Have you tried using

 gem install mysql -- --with-mysql-lib=/usr/lib/mysql/lib 

to specify the location of thebase directory as well as the path to the MySQL libraries that are necessary to complete the gem installation?

Sources: MySQL Gem Install ERROR: Failed to build gem native extension MySQL Forums :: Ruby :: Help needed with installing MySQL binding for Ruby

Hal
as much as I understand "mysql" and "mysql2" are different gems. I have even tried "gem install mysql2 -- --with-mysql-lib=/usr/lib/mysql/lib" but still the same error
spacemonkey
+5  A: 

Following line solved the issue:

sudo apt-get install libmysql-ruby libmysqlclient-dev
spacemonkey
+1  A: 

Same issue on Windows 7

acidrain
A: 

I was running into this error on my mac and found that I needed to upgrade from mysql 32bit to mysql 64 bit to get this error to go away. I was running OSX 10.6 on an intel macbook pro with ruby 1.9.2 and rails3.0.0

I also needed to install xcode in order to get unix utilities like "make" that are required to compile the gem.

once this was done I was able to run gem install mysql and gem install mysql2 without error.

smokeysonora
ruby 1.6.2 or ruby 1._9_.2?
Tim Snowhite
ruby 1.9.2 edited my answer to reflect. thanks!
smokeysonora
A: 

I got this error too. Solved by installing development packages. I'm using arch and it was:

sudo pacman -S base-devel

which installed:

m4, autoconf, automake, bison, fakeroot, flex, libmpc, ppl, cloog-ppl, elfutils, gcc,
libtool, make, patch, pkg-config

but I think it actually needed make and gcc. Error output said (on my machine, among other):

"You have to install development tools first."

So it was an obvious decision and it helped.

arty