2010-09-20 66 views
60

我试图安装通过捆扎机的mysql2宝石,但它一直与以下错误垂死:错误通过所述捆绑安装mysql2宝石

** executing command 
/home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/installer.rb:483:in 'rescue in block in build_extensions': 
ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError) 

/home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb --with-mysql-config=/usr/bin/mysql_config 
checking for rb_thread_blocking_region()... yes 
checking for mysql.h... no 
checking for mysql/mysql.h... no 

----- 
mysql.h is missing. please check your installation of mysql and try again. 
----- 

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

Provided configuration options: 
--with-opt-dir 
--without-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 
--srcdir=. 
--curdir 
--ruby=/home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/bin/ruby 
--with-mysql-config 
Gem files will remain installed for inspection. 

我发现通过谷歌搜索建议传递--with-mysql-config参数大部分事情修理它。因此,基于:

$ which mysql_config 
/usr/bin/mysql_config 

我增加了以下内容,所述捆绑的配置:

$ bundle config build.mysql2 --with-mysql-config='/usr/bin/mysql_config' 

但是,仍然没有运气 - 同上崩溃。

由于它正在死于错误mysql.h is missing,我检查了它,据说它在周围,只是不能被Bundler发现。

$ find/-name mysql.h 
/usr/include/mysql5/mysql/mysql.h 

有什么想法?

+2

你在http://stackoverflow.com/questions/3608287/installing-mysql2-gem-for-rails-3上试过解决方案吗? – Wrikken 2010-09-20 21:01:27

+0

否则,你可能只编辑'ext/mysql2/extconf.rb'并自己输入正确的路径到你的mysql目录(它靠近顶部)。 – Wrikken 2010-09-20 21:03:48

回答

95

答案类似于Wrikken发布的 - 这是我为了未来的读者而修复它的。

(这是RHEL 5.5 - 类似,但不同的命令申请的Ubuntu/Debian上的/ etc。)

sudo yum list installed将打印出您的计算机上的所有已安装的软件包(注:yum在RHEL上需要你添加一个红帽网络存储库[我使用EPEL],并通过sudo运行它)。

我有mysqlmysql-server,这解释了为什么MySQL的每一个预先存在的应用程序工作正常,但没有mysql-devel,这是必要的修复mysql.h is missing错误和其他类似的生成错误。

长话短说,一个mysqldump -u root -ppassword --all-databases > full-dump.sql为安全后,将其固定用一个简单的

sudo yum install mysql-devel 
+0

工程太棒了!非常感谢! – 2011-04-04 20:16:44

+9

在mac中,执行'brew install mysql' http:// stackoverflow。com/questions/3608287/installed-mysql2-gem-for-rails-3 – 2012-06-01 18:29:21

+0

在我的安装中,安装了'mysql-devel',但是'/ usr/include/mysql'是空的。 'mysql.h'位于'/ usr/include/mysql51'中。所以我跑了'sudo rmdir/usr/include/mysql; sudo ln -s/usr/include/mysql51/usr/include/mysql'和瞧! Mysql2现在可以正常构建。 – Zee 2012-09-28 17:26:15

33

的Ubuntu必须安装以下。 的libmysqlclient-dev的 libmysqlclient16

+0

完美。为我工作。 – Zabba 2011-01-02 09:51:15

+0

+1谢谢,你救了我的一天:-) – 2013-03-12 02:54:55

+0

当我在Ubuntu 16.04上尝试这个时,没有'libmysqlclient16',只有'libmysqlclient20'。我怀疑,只要更新后的版本不会破坏任何内容,无论您使用哪种版本的Ubuntu,像'sudo apt-get install'libmysqlclient *''都会安装所需的软件包。 – mwfearnley 2016-06-18 16:26:14

0

我知道这是古老的,但如果有人仍然得到这个zlib的错误,请确保您键入: RVM使用

(任何版本你正在使用)

我可以发誓我做到了。只要张贴,以防有人拉出头发,这有助于。如果不是好运。 :)

8

上述问题将发生,因为mysql-devel软件包未正确安装在您的系统中。我将在CentOS中解释如何解决这个问题。当您尝试安装该软件包使用,

yum install mysql-devel 

somtimes会有用,如果你安装的MySQL管理工具和MySQL查询浏览器,被安装在现有的包发生了一些冲突。

在这种情况下,您需要卸载所有现有的mysql2包并重新安装。

rpm -qa -last | grep -i mysql 
    yum remove MySQL-server-5.5.27-1.rhel5 
    yum remove MySQL-client-5.5.27-1.rhel5 
    yum remove mysql-gui-tools-5.0r12-1rhel4 
    yum remove mysql-query-browser-5.0r12-1rhel4-a 

所以,你可以像上面那样卸载任何与rpm -qa一起显示的mysql事物。

然后你可以安装mysql-server和mysql-client。

yum install mysql-server 
    yum install mysql-client 

现在你开始安装mysql-devel软件包。

yum install mysql-devel 

现在没有包装冲突,你可以安装mysql2宝石。

gem install mysql2 -v '0.3.11' 

现在你的mysql2宝石将被成功安装,你很好去。

1

在我的情况下,问题是一个行为不正确的mysql_config脚本。当通过与--cflags选项从命令行调用它会返回包含选项的字符串:

-Xclang -target-feature -Xclang -aes -Qunused-arguments

出于某种原因调用have_header在extconf.rb脚本(“的mysql.h”)会失败如果包含这些选项的话。

什么工作对我来说是手工编辑mysql_config文件中删除引用来自行这些选项:

cflags="-I$pkgincludedir -Os -w -pipe -march=native -Xclang -target-feature -Xclang -aes -Qunused-arguments -O2 -g -DDBUG_OFF " #note: end space!

我作为改写:

cflags="-I$pkgincludedir -Os -w -pipe -march=native -O2 -g -DDBUG_OFF " #note: end space!
20

对于Mac与酿造安装下面的解决方案解决了我的问题:

我编辑了/usr/local/Cellar/mysql/5.6.12/bin中的mysql_config文件并删除了W编译器选项-Wno-nul l转换和-Wno-unused-private-field用于cflags和cxxflags。

这解决了“gem install mysql2”的问题。

参考:http://www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html

+1

适合我。谢谢! – taiansu 2013-06-27 18:04:46

+0

我也是!谢谢,救了我的一天! – 2013-08-27 10:42:12

0

我就遇到了这个问题,而捆绑在Fedora 23上安装的管理平台,我发现的解决方案是发出此命令 - sudo dnf install redhat-rpm-config

这不仅解决了我安装mysql2的问题,而且解决了nokogiri和redcarpet的问题。

1

我得到了同样的错误。并为Ubuntu 16.我不得不写下面的命令:

sudo apt-get install libmysqlclient-dev 

它的工作原理。

相关问题