gem install mysql2失败

时间:2011-03-07 12:43:02

标签: mysql ubuntu gem

我收到了这个错误:

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

/usr/bin/ruby1.8 extconf.rb
checking for rb_thread_blocking_region()... no
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=/usr/bin/ruby1.8
    --with-mysql-config
    --without-mysql-config


Gem files will remain installed in /var/lib/gems/1.8/gems/mysql2-0.2.6 for inspection.
Results logged to /var/lib/gems/1.8/gems/mysql2-0.2.6/ext/mysql2/gem_make.out

我试过了:

  • 卸载mysql2并重新安装
  • 使用apt-get
  • 卸载mysql
  • 来自mysql的installd dev-tools
  • 以及Google上的几乎所有网页

我该如何解决这个问题?

8 个答案:

答案 0 :(得分:92)

在安装libmysqlclient-dev gem:

之前,您需要安装mysql2
sudo apt-get install libmysqlclient-dev
gem install mysql2

这应该可以在最新的Ubuntu版本上解决这个问题。

答案 1 :(得分:9)

感谢Andre Schweighofer,只是为了它

sudo apt-get install libmysqlclient-dev
gem install mysql2

..
bundle update
bundle install

完成!!!

答案 2 :(得分:3)

需要安装mysql开发包

yum install mysql-devel

答案 3 :(得分:1)

在此处使用搜索会很有帮助;):ruby-mysql

这是另一个线程;)具有相同的问题:ruby-mysql2

以及搜索“ruby mysql2”或类似内容时的更多内容。

答案 4 :(得分:1)

这是造成这种失败的多种原因:

  1. ruby​​和rubygems之间的错误版本兼容性
  2. 缺少libmysqlclient-dev
  3. gem找不到
  4. 64位系统上的Mysql 32位
  5. 解决方案

    1. 使用最新的稳定版本安装rvm,您可以在ruby版本之间通过rvm切换

        

      curl -L https://get.rvm.io | bash -s stable

    2. 安装dependecy

        

      sudo apt-get install libmysqlclient-dev

    3. 在您的系统上找到mysql_config(找到/ -name mysql_config)并运行
        

      gem install mysql -- --with-mysql-config=/path/to/mysql_config

    4.   
    5. 为您的系统安装64位版本的mysql
    6.   

答案 5 :(得分:0)

在Ubuntu 10.10上,我必须安装libmysqlclient16-dev。

答案 6 :(得分:0)

我解决的方法是检查mkmf.log,在我的情况下是在某处 ./gems/ruby-2.2.3/extensions/x86_64-linux/2.2.0/mysql2-0.4.2/mkmf.log

在我的情况下,有一个错误,它找不到-lgmp,所以它缺少gmp库,所以通过apt-get安装,在本例中为libgmp-dev。

答案 7 :(得分:0)

这可能是由于mysql更新了二进制文件(在我的情况下它使用的是Mariadb-10.0.31)并且在安装缺少的库(libmysqlclient-dev)时,我得到以下消息:它将无法解决:< / p>

$ sudo apt-get install libmysqlclient-dev

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libmysqlclient-dev : Depends: libmysqlclient18 (= 5.5.58-0ubuntu0.14.04.1)

但我首先安装 libmariadbclient-dev 解决了上述问题: -

 $ sudo apt-get install libmariadbclient-dev

它也会安装 libmysqlclient-dev ,但首先要解决mariadb依赖问题。