错误:安装mysql2时出错:错误:无法构建原生扩展宝石

11
我在尝试为Rails安装gem install mysql2 -v '0.3.17'时遇到了一些问题。当我运行gem install mysql2 -v '0.3.17'或gem install mysql2 -v '0.3.17'来安装它时,它会给我以下错误提示:
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.


Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysql-config
    --without-mysql-config

Gem files will remain installed in `..../gems/ruby-1.9.3-p392/gems/mysql2-0.3.17 for inspection`.
Results logged to `.../gems/ruby-1.9.3-p392/extensions/x86_64-darwin-14/1.9.1/mysql2-0.3.17/gem_make.out`

我该如何解决这个问题并成功安装mysql2?

谢谢大家。


你能否包含 .../gems/ruby-1.9.3-p392/extensions/x86_64-darwin-14/1.9.1/mysql2-0.3.17/gem_make.out 文件的内容?它在错误信息的最后一行显示为 Results logged to.. - Prakash Murthy
这应该会有所帮助:https://dev59.com/MG855IYBdhLWcg3w1oLa - Prakash Murthy
4个回答

10

我在Ubuntu 15.04中,遇到了与上述情况相同的错误。

我执行了以下操作:

 sudo apt-get install libmysqlclient-dev 

之后我做了:

gem install mysql2

现在我可以成功地做到

rails new <app_name> -d mysql

没有任何错误。


8

安装libmysqlclient-devel:

CentOS/Fedora:

yum install -y libmysqlclient-devel

Ubuntu:

apt-get install -y libmysqlclient-dev

Mac:

brew install mysql

希望它有所帮助。

这是mysql2 gem所必需的。只需在gem install mysql2rails new app_name -d mysql之前安装它即可。 - bestmike007
在 Fedora 上,这对我起作用:yum install mysql-devel。(或者更准确地说:dnf install mysql-devel - kingsfoil

3

你好,这可能有两个原因。

1)你没有安装mysql服务器,请尝试安装。

$ brew install mysql

2) 在尝试安装mysql2时没有指定mysql_config,可以尝试使用以下命令:

$ gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql/5.6.24/bin/mysql_config

2

首先,您需要安装MySQL服务器。可能目前您还没有安装它。


谢谢,我有mysql但没有mysql2。 - Thanh Khiet Nguyen
去Oracle网站下载并安装它,然后gem就可以安装了。 - Lukasz Muzyka

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接