I am having some problems when trying to install mysql2
gem for Rails. When I try to install it by running bundle install
or gem install mysql2
it gives me the following error:
Error installing mysql2: ERROR: Failed to build gem native extension.
How can I fix this and successfully install mysql2
?
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.
After you get the mysql-dev issues corrected, you may need to remove the bad mysql2 install. Look carefully at the messages after $ bundle install. You may need to
This will clear out the bad mysql2 installation so that a final $ bundle install can create a good one.
Another way for MacOS users
If you used "brew" to install mysql:
x.x.x = version of the mysql2 gem you want to install
y.y.y = the version of mysql you have installed
ls /usr/local/Cellar/mysql
to find it.For those using Windows 7 and 64-bit MySQL
If you want to use 64-bit MySQL, you should follow the instructions here (also here).
There is also a custom built 64-bit connector that works without hassle.
Got the "You have to install development tools first." error when trying to install the mysql2 gem after upgrading to Mac OS X Mountain Lion. Apparently doing this upgrade removes the command line compilers.
To fix:
I have several computers, 32 and 64 bits processor, they run on Ubuntu Linux, Maverick (10.10) release.
I had the same problem, and for me, the
sudo apt-get install libmysql-ruby libmysqlclient-dev
did the job!!!