我收到此错误:
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
我已经尝试过:
我该如何解决这个问题?
在安装
libmysqlclient-dev
gem 之前需要先安装 mysql2
:
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
导致此失败的原因有多种:
解决方案
安装最新稳定版本的rvm,您可以通过rvm在ruby版本之间切换
curl -L https://get.rvm.io | bash -s stable
安装依赖
sudo apt-get install libmysqlclient-dev
gem install mysql -- --with-mysql-config=/path/to/mysql_config
这可能是由于 mysql 更新了二进制文件(在我的例子中它使用的是 Mariadb-10.0.31)并且在安装缺少的库( libmysqlclient-dev )时,我收到以下消息,无法解决:
$ 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 依赖关系。
在 Ubuntu 10.10 上,我必须安装 libmysqlclient16-dev。
我解决的方法是检查 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。
在 Debian 12 中
libmysqlclient-dev 包不可用,但被另一个包引用。 这可能意味着该包丢失、已过时或只能从其他来源获得 然而,以下软件包取代了它: libmariadb-dev-compat libmariadb-dev
sudo apt-get install libmariadb-dev-compat libmariadb-dev
gem安装mysql2