当前位置: 首页>>技术教程>>正文


gem安装mysql2失败

, ,

问题描述

我收到此错误:

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安装了dev-tools

  • 以及Google上几乎所有的页面

我怎样才能解决这个问题?

最佳解决思路

在安装mysql2 gem之前,您需要安装libmysqlclient-dev

sudo apt-get install libmysqlclient-dev
gem install mysql2

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

次佳解决思路

感谢Andre Schweighofer,仅此而已

sudo apt-get install libmysqlclient-dev
gem install mysql2

..
bundle update
bundle install

完成!

第三种解决思路

需要安装mysql开发包

yum install mysql-devel

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/7506.html,未经允许,请勿转载。