gem install mysql 报extconf.rb failed错误

今天更新redmine的时候,需要安装mysql gem包。

结果一直报错:

Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
    ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.8 extconf.rb --with-mysql-config=/usr/local/mysql/bin/mysql_config
extconf.rb:10: command not found: /usr/local/mysql/bin/mysql_config --cflags
*** 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=/usr/bin/ruby1.8
    --with-mysql-config

在用尽我对ruby可怜的已知知识之后,开始google,尝试了第一种方法:

http://blog.bmn.name/2008/02/rails-gem-install-mysql-throws-error-extconfrb-failed/

但是我痛苦地发现我使用deb包安装的mysql没有mysql_config这个文件夹。

接着在万能的stackoverflow上找到了解决办法:

http://stackoverflow.com/questions/5795309/gem-install-mysql-fail

安装了mysql客户端的dev库包:

 sudo apt-get install libmysqlclient-dev
# 该包的描述是:This package includes development libraries and header files.

然后就欢快地通过了gem install mysql~

PS:同理,如果安装Postgresql的pg gem包时,如果缺少libpq-dev包,也会导致同样的错误。

None
原文地址:https://www.cnblogs.com/yuxc/p/2726451.html