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:53

I'm on a mac and use homebrew to install open source programs. I did have to install mac Dev tools in order to install homebrew, but after that it was a simple:

brew install mysql

to install mysql. I haven't had a mysql gem problem since.

查看更多
低头抚发
3楼-- · 2018-12-31 09:55

If you are using yum try:

sudo yum install mysql-devel
查看更多
一个人的天荒地老
4楼-- · 2018-12-31 09:55

For windows user: You set the lib and include path of your mysql, for instance, if youre using xampp you can have like this:

gem install mysql2 -- '--with-mysql-lib="C:\xampp\mysql\lib" --withmysql-include="C:\xampp\mysql\include"'
查看更多
还给你的自由
5楼-- · 2018-12-31 09:56

You have to Install some dependencies

sudo apt-get install libmysql-ruby libmysqlclient-dev
查看更多
看淡一切
6楼-- · 2018-12-31 09:56

Solution only works on Mac OS X

If you've installed MySQL with homebrew, what worked for me was uninstalling MySQL, and installing MySQL Community Edition via the MySQL website (https://www.mysql.com/).

After installed, just re-enter the command to gem install mysql2 or if necessary, sudo gem install mysql2, if you are getting permission denied problems.

查看更多
低头抚发
7楼-- · 2018-12-31 09:56

You are getting this problem because you have not install MySql. Before install mysql2 gem. Install MySQL. After that mysql2 gem will install.

查看更多
登录 后发表回答