【问题标题】:Ruby gem mysql2 install failingRuby gem mysql2 安装失败
【发布时间】:2011-05-06 03:12:30
【问题描述】:

当我尝试安装 mysql2 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.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... no
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
    --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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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 /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/ext/mysql2/gem_make.out

【问题讨论】:

    标签: mysql ruby rubygems mysql2 libmysql


    【解决方案1】:

    Ubuntu:

    sudo apt-get install libmysqlclient-dev  #(mysql development headers)
    sudo gem install mysql2 -- --with-mysql-dir=/etc/mysql/
    

    就是这样!

    结果:

    Building native extensions. This could take a while...
    Successfully installed mysql2-0.2.6
    1 gem installed
    Installing ri documentation for mysql2-0.2.6...
    Enclosing class/module 'mMysql2' for class Result not known
    Enclosing class/module 'mMysql2' for class Client not known
    Installing RDoc documentation for mysql2-0.2.6...
    Enclosing class/module 'mMysql2' for class Result not known
    Enclosing class/module 'mMysql2' for class Client not known
    

    【讨论】:

    • 不幸的是,apt 在 OSX 上尚不可用。但是您的方法确实适用于 Debian/Ubuntu。
    • 我不明白当它与问题不对应时,它怎么会有这么多的赞成票。
    • 它有很多赞成票,因为其他人(比如我自己)发现这很有用。它解决了我的问题。
    • 问题是同一个问题,但在不同的操作系统上
    • 请不要在 Ubuntu 13 上这样做,至少,您不必指定 with-mysql-dir。只需安装libmysqlclient-dev 然后运行bundle install 就可以了。
    【解决方案2】:

    您需要 mysql2 的 MySQL 开发头文件才能正确编译。这是必需的,因为大部分功能都是用 C 语言编写的,然后与 MySQL 相关联。

    一种解决方案是将 gem 安装程序明确指向您的 mysql 安装文件夹,如下所示

    gem install mysql2 -- --with-mysql-dir=/usr/local/mysql
    # or where ever you installed your mysql server to
    

    或通过将 mysql 服务器安装到已知位置(例如,通过使用 homebrew.)然后安装 gem

    # install the mysql server locally
    brew install mysql
    # install the gem
    gem install mysql2
    

    这两种方法都要求您安装 XCode 才能拥有所需的 GCC 编译器。

    【讨论】:

    • 冲泡解决方案对我来说效果最好。如果您安装 Mac OS X MySQL 二进制文件,请确保使用 64 位版本。
    • 谢谢,--with-mysql-dir= 选项正是我解决问题所需要的。
    • 对我来说,--with-mysql-dir 实际上导致了一个问题。我只是将其关闭并让它安装到默认目录。我只是用gem install mysql2 -v '0.3.18'直接安装了一个特定的版本
    • 谢谢:这对我有用:==> sudo gem install mysql2 -- --with-mysql-dir=/usr/local/mysql
    【解决方案3】:

    您的机器上必须安装 64 位 MySQL,以及安装 xcode 时获得的构建工具。

    【讨论】:

    • 解决了。通过下面的链接在我的计算机上安装了 64 位 MySQL,一切正常。谢谢!
    • 是的 - brew install mysql 然后gem install mysql 没有问题 - 谢谢!
    【解决方案4】:

    安装 Brew 和 MySQL 后,我使用以下命令安装 mysql2 gem

    gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql/5.5.10/bin/mysql_config
    

    如果您使用的是 Bundler,您可以使用以下命令告诉 bundler:

    bundle config build.mysql2 --with-mysql-config=/usr/local//Cellar/mysql/5.5.10/bin/mysql_config
    

    如此处所述:http://gembundler.com/man/bundle-config.1.html

    【讨论】:

    • 如果您使用 brew 版本安装旧版本,这也适用,例如brew install mysql51, gem install mysql2 -v '0.3.13' -- --with-mysql-config=/usr/local/Cellar/mysql51/5.1.71/bin/mysql_config(山狮)
    • MacOS 中这个奇怪问题的唯一解决方案!
    【解决方案5】:

    在 Mac OSX Moutain Lion 上,以下命令对我有用:

    gem install mysql2 -- --srcdir=/usr/local/mysql/include
    

    【讨论】:

    • Ubuntu 14.01 也是如此!
    • 在 macOS Mojave 上也是如此!
    【解决方案6】:

    Ubuntu 15.04:

    sudo apt-get install libmysqlclient-dev
    sudo gem install mysql2
    

    Ubuntu-16.04:

    sudo apt-get install ruby-mysql2
    sudo gem install mysql2
    

    输出:

    Building native extensions.  This could take a while...
    Successfully installed mysql2-0.3.19
    Parsing documentation for mysql2-0.3.19
    Installing ri documentation for mysql2-0.3.19
    Done installing documentation for mysql2 after 0 seconds
    1 gem installed
    

    【讨论】:

      【解决方案7】:

      您可能想在 MySQL 网站上查看此线程:http://forums.mysql.com/read.php?116,178217,178217,尤其是 Scott Derrick 的回答:http://forums.mysql.com/read.php?116,178217,189357#msg-189357

      更具体地说,尝试使用

      sudo gem install mysql2 -- --with-mysql-dir=/usr/local/mysql
      

      希望对您有所帮助。

      【讨论】:

        【解决方案8】:

        我在互联网和 Stack Overflow 上挖了 2 天,直到我找到 this link 然后开始通过 this ticket for mysql2 工作,我才真正解决了这个问题。

        使用我的设置(如票证中所述),-Wno-null-conversion -Wno-unused-private-field 的编译器开关会中断并给我一个不完全正确的错误,即:

        mysql.h is missing. please check your installation of mysql and try again
        

        【讨论】:

          【解决方案9】:

          我通过指定目录在哪里解决了这个问题,不需要重新安装任何东西,使用 brew 或 macports 或其他任何东西,只需指定东西在哪里(只有一件事:红宝石我的mac是用rvm安装的,我没有使用os x自带的默认):

          将下面的标志添加到您的gem install mysql2

          • --srcdir="..." - 包括
          • --with-mysql-dir="..." - mysql目录
          • --with-mysql-config="..." - mysql_config 文件

          喜欢这个gem install mysql2 --srcdir=/usr/local/mysql/include/ --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

          【讨论】:

            【解决方案10】:

            在 Centos 6.x(7 应该可以工作)中使用 SCL(软件集合)rh-mysql:

            scl enable rh-mysql56 bash
            gem install mysql2 -v '0.4.5' -- --with-mysql-include=/opt/rh/rh-mysql56/root/usr/include --with-mysql-lib=/opt/rh/rh-mysql56/root/usr/lib64
            

            【讨论】:

              【解决方案11】:

              我猜如果你在目录中输入rvm use ruby-2.1.0@rails4.0 --create,那么bundle install 就可以了。

              【讨论】:

                猜你喜欢
                • 2011-12-03
                • 1970-01-01
                • 2015-11-29
                • 2012-05-21
                • 2011-04-09
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多