错误:无法建立宝石原生扩展(on Rails的3.2.3 mysql2)(ERROR: Failed

2019-06-23 11:07发布

我试图安装使用Rails 3.2.3 mysql2宝石和它的失败:

★  bundle install
Fetching gem metadata from https://rubygems.org/.........
Using rake (0.9.2.2) 
Using i18n (0.6.0) 
Using multi_json (1.2.0) 
Using activesupport (3.2.3) 
Using builder (3.0.0) 
Using activemodel (3.2.3) 
Using erubis (2.7.0) 
Using journey (1.0.3) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.1) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.1.2) 
Using actionpack (3.2.3) 
Using mime-types (1.18) 
Using polyglot (0.3.3) 
Using treetop (1.4.10) 
Using mail (2.4.4) 
Using actionmailer (3.2.3) 
Using arel (3.0.2) 
Using tzinfo (0.3.32) 
Using activerecord (3.2.3) 
Using activeresource (3.2.3) 
Using bundler (1.1.3) 
Using coffee-script-source (1.2.0) 
Using execjs (1.3.0) 
Using coffee-script (2.2.0) 
Using rack-ssl (1.3.2) 
Using json (1.6.6) 
Using rdoc (3.12) 
Using thor (0.14.6) 
Using railties (3.2.3) 
Using coffee-rails (3.2.2) 
Using jquery-rails (2.0.2) 
Installing mysql2 (0.3.11) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/rarneson/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb 
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** 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
    --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=/Users/rarneson/.rvm/rubies/ruby-1.9.3-p125/bin/ruby
    --with-mysql-config
    --without-mysql-config
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mlib
    --without-mlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-zlib
    --without-zlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-socketlib
    --without-socketlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-nsllib
    --without-nsllib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mygcclib
    --without-mygcclib
    --with-mysqlclientlib
    --without-mysqlclientlib


Gem files will remain installed in /Users/rarneson/.rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/rarneson/.rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
An error occured while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.

我正在捆绑安装,这是在我的Gemfile:

gem 'mysql2', '~> 0.3.11' 

我目前得到通过MAMP运行MySQL。 我不知道这是一个坏主意,我应该运行香草MySQL,但似乎我目前的问题是刚开安装了宝石。 我见过不少的在这里计算器这些问题,但似乎都有些不同,或者有非常复杂的解决方案。 是否有什么我失踪? 简单的东西? 一些愚蠢的事? 我可以从出文件,如果需要提供额外的信息。 我读过,有些人使用SQLite的开发和测试,然后在MySQL督促,但听起来像一个非常可怕的想法。

Answer 1:

从https://github.com/brianmario/mysql2/issues/8

只需在控制台中复制此

sudo apt-get install mysql-client libmysqlclient-dev

和工作!



Answer 2:

我用自制的Mac安装mysql:

brew install mysql

然后我用宝石命令来安装mysql2宝石:

sudo gem install mysql2


Answer 3:

这主要是由于缺乏mysql的头,尝试安装MySQL的开发者(的mysql-devel的)包

通常,当“的libmysqlclient-dev的”包丢失这个错误出现

  • 如果你是在Linux上尝试此链接
  • 如果你是在Windows这个网址可以帮助你


Answer 4:

我只是碰到了同样的问题,使用OS X塞拉利昂和甲基苯丙胺和Rails 5.我通过成功安装了宝石

gem install mysql2 -- --with-mysql-config=/Applications/MAMP/Library/bin/mysql_config

在此之后,捆绑安装工作就好了。



Answer 5:

我结束了刚刚安装MySQL的新副本,而不是使用MAMP,并且做的伎俩。 还必须确保安装64位版本,而不是32位。



Answer 6:

你可以按照这个线程错误通过捆扎机安装mysql2宝石这解释为CentOS的解决方案,这一问题将是固定的,如果你调整的命令WRT您的操作系统,你可以能够成功安装mysql2宝石。



Answer 7:

只需MAMP MySQL的添加到PATH,那么你就可以运行安装包按正常。

$ /应用程序/ MAMP /库/斌/ MySQL的主机=本地主机-uroot -proot

来源: http://blog-en.mamp.info/2009/08/using-mysql-command-line-with-mamp.html



Answer 8:

当我得到这个错误,我可以通过运行解决这个问题:

gem install devtools


文章来源: ERROR: Failed to build gem native extension (mysql2 on rails 3.2.3)