简体   繁体   English

错误:无法构建 gem 本机扩展(rails 3.2.3 上的 mysql2)

[英]ERROR: Failed to build gem native extension (mysql2 on rails 3.2.3)

I'm trying to install the mysql2 gem with Rails 3.2.3 and it's failing:我正在尝试使用 Rails 3.2.3 安装 mysql2 gem 但它失败了:

★  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.

I'm running bundle install and this is in my Gemfile:我正在运行 bundle install,这是在我的 Gemfile 中:

gem 'mysql2', '~> 0.3.11' 

I've currently got MySQL running through MAMP.我目前有 MySQL 通过 MAMP 运行。 I'm not sure if this is a bad idea and I should run a vanilla MySQl but it seems my current problem is just getting the gem installed.我不确定这是否是个坏主意,我应该运行 vanilla MySQl 但似乎我当前的问题只是安装 gem。 I've seen quite a few of these problems here on stackoverflow but all seem a bit different or have really complicated solutions.我在 stackoverflow 上看到了很多这样的问题,但看起来都有点不同或者有非常复杂的解决方案。 Is there something I'm missing?有什么我想念的吗? Something simple?简单的东西? Something stupid?愚蠢的东西? I can provide additional info from the out file if necessary.如有必要,我可以提供 out 文件中的其他信息。 I've read that some people use SQLite for dev and test then MySQL in prod but that sounds like a pretty horrible idea.我读到有人在开发和测试中使用 SQLite,然后在产品中使用 MySQL,但这听起来像是一个非常糟糕的想法。

From https://github.com/brianmario/mysql2/issues/8来自https://github.com/brianmario/mysql2/issues/8

just copied this in the console刚刚在控制台中复制了这个

sudo apt-get install mysql-client libmysqlclient-dev

and worked!!并工作!

I used Homebrew for Mac to install mysql:我使用Homebrew for Mac安装 mysql:

brew install mysql

Then I used a gem command to install the mysql2 gem:然后我使用 gem 命令安装 mysql2 gem:

sudo gem install mysql2

This is mostly due to lack of mysql headers, Try to install mysql developer (mysql-devel) packages这主要是由于缺少 mysql 标头,尝试安装 mysql 开发人员 (mysql-devel) 包

Normally this error comes when 'libmysqlclient-dev' package is missing通常,当缺少“libmysqlclient-dev”package 时会出现此错误

I just ran into the same problem, using OS X Sierra and MAMP and Rails 5. I successfully installed the gem via我刚刚遇到了同样的问题,使用 OS X Sierra 和 MAMP 和 Rails 5。我通过以下方式成功安装了 gem

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

After that, bundle install worked just fine.在那之后, bundle install 工作得很好。

I ended up just installing a fresh copy of MySQL and not using MAMP and that did the trick.我最终只安装了 MySQL 的新副本,没有使用 MAMP,这就成功了。 Also had to be sure to install the 64-bit version, not 32-bit.还必须确保安装 64 位版本,而不是 32 位版本。

You can follow this thread Errors Installing mysql2 gem via the Bundler which explains the solution for Centos and this problem will be fixed, if you tweak the commands w.r.t your OS and you can be able to successfully install the mysql2 gem.您可以关注此线程Errors Installing mysql2 gem via the Bundler ,它解释了 Centos 的解决方案,如果您调整命令 w.r.t 您的操作系统,您就可以成功安装 mysql2 gem。

Just add MAMP mysql to PATH, then you can run bundle install as per normal.只需将 MAMP mysql 添加到 PATH,然后就可以正常运行 bundle install。

$ /Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot $ /Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot

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

When I got this error, I was able to fix this by running:当我收到此错误时,我可以通过运行以下命令来解决此问题:

gem install devtools

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 安装mysql2 gem时出错:无法构建gem原生扩展 - Error installing mysql2 gem: Failed to build gem native extension 安装mysql的Rails - 安装mysql2时出错:错误:无法构建gem原生扩展 - Rails installing mysql - Error installing mysql2: ERROR: Failed to build gem native extension 错误:无法构建 gem 原生扩展 - 安装 mysql2 时出错 - ERROR: Failed to build gem native extension - Error installing mysql2 安装 mysql2 时出错:无法构建 gem 原生扩展 - Error installing mysql2: Failed to build gem native extension 错误:安装mysql2时出错:错误:无法构建gem原生扩展。 在Mac 10.12上 - ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. on Mac 10.12 错误:安装mysql2时出错:错误:无法构建gem原生扩展 - ERROR: Error installing mysql2: ERROR: Failed to build gem native extension 无法在 Mysql Docker 容器中安装 mysql2 gem:无法构建 gem 本机扩展 - Cannot install mysql2 gem inside Mysql Docker container: Failed to build gem native extension mysql2 gem无法在Windows 7上安装:无法生成gem本机扩展 - mysql2 gem failing to install on Windows 7: failed to build gem native extension 错误:安装mysql时出错:错误:无法构建gem本机扩展 - ERROR: Error installing mysql: ERROR: Failed to build gem native extension MySQL 安装:错误:无法构建 gem 原生扩展 - MySQL Install: ERROR: Failed to build gem native extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM