Error installing mysql2: Failed to build gem nativ

2018-12-31 09:19发布

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?

25条回答
宁负流年不负卿
2楼-- · 2018-12-31 10:04

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.

查看更多
步步皆殇っ
3楼-- · 2018-12-31 10:05

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

rm -rf vendor/cache/
rm -rf ./Zentest

This will clear out the bad mysql2 installation so that a final $ bundle install can create a good one.

查看更多
千与千寻千般痛.
4楼-- · 2018-12-31 10:06

Another way for MacOS users

If you used "brew" to install mysql:

gem install mysql2 -v 'x.x.x' -- --with-mysql-config=/usr/local/Cellar/mysql/y.y.y/bin/mysql_config

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.

查看更多
君临天下
5楼-- · 2018-12-31 10:09

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.

查看更多
看风景的人
6楼-- · 2018-12-31 10:10

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 uninstalled my very old version of Xcode (ran the uninstall script in /Developer/Library). Then deleted the /Developer directory.
  • Went to the AppStore and downloaded Xcode.
  • Launched Xcode and went into the Preferences -> Downloads, and installed the command line tools.
查看更多
只若初见
7楼-- · 2018-12-31 10:11

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!!!

查看更多
登录 后发表回答