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 09:58

libmysql-ruby has been phased out and replaced. New command:

 sudo apt-get install ruby-mysql libmysqlclient-dev
查看更多
只若初见
3楼-- · 2018-12-31 09:59

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

查看更多
不再属于我。
4楼-- · 2018-12-31 09:59

I had this issue with my windows 7. This is apparently an incompatibility issue and the solution is as follows: Download mysql.dll file from an older InstantRails installer. The Link http://tinyurl.com/24ocp8u will download only the mysql.dll file.(It's link to svn repository of InstantRails). Next, copy that filw into your Ruby/bin folder. Now, you are good to go ;)

查看更多
公子世无双
5楼-- · 2018-12-31 10:00

If still getting error then follow the steps of mysql2 gem installation on Rails 3 on -

http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html

where most of the user were able to install mysql2 gem.

查看更多
冷夜・残月
6楼-- · 2018-12-31 10:01

On Ubuntu/Debian and other distributions using aptitude:

sudo apt-get install libmysql-ruby libmysqlclient-dev

Package libmysql-ruby has been phased out and replaced by ruby-mysql. This is where I found the solution.

If the above command doesn't work because libmysql-ruby cannot be found, the following should be sufficient:

sudo apt-get install libmysqlclient-dev

On Red Hat/CentOS and other distributions using yum:

sudo yum install mysql-devel

On Mac OS X with Homebrew:

brew install mysql
查看更多
琉璃瓶的回忆
7楼-- · 2018-12-31 10:02

If you are still having trouble….

Try installing

   sudo apt-get install ruby1.9.1-dev
查看更多
登录 后发表回答