如何在Ruby 1.9.3下安装mysql2 gem?在2.0.0下工作

时间:2013-06-25 16:55:52

标签: ruby bundler homebrew mysql2

我在我的机器上安装mysql2 gem时遇到了麻烦。

我的OS X 10.8包含最新的Xcode,而mySql是通过Homebrew安装的。使用最新的RVM安装所有rubies。

我可以在ruby 2.0.0-p195

下安装mysql2
[~]$ rvm use 2.0.0                                                              [ruby-1.9.3-p429]
Using /Users/aselder/.rvm/gems/ruby-2.0.0-p195
[~]$ gem in mysql2                                                              [ruby-2.0.0-p195]
Fetching: mysql2-0.3.11.gem (100%)
Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.11
1 gem installed

在Ruby 1.9.3和1.8.7下,找不到mysql.h文件

    [~]$ rvm use 1.9.3                                                              [ruby-1.9.3-p429]
    Using /Users/aselder/.rvm/gems/ruby-1.9.3-p429
    [~]$ gem in mysql2                                                              [ruby-1.9.3-p429]
    Fetching: mysql2-0.3.11.gem (100%)
    Building native extensions.  This could take a while...
    ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

            /Users/aselder/.rvm/rubies/ruby-1.9.3-p429/bin/ruby extconf.rb
    checking for rb_thread_blocking_region()... yes
    checking for rb_wait_for_single_fd()... yes
    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
        --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/aselder/.rvm/rubies/ruby-1.9.3-p429/bin/ruby
        --with-mysql-config
        --without-mysql-config


    Gem files will remain installed in /Users/aselder/.rvm/gems/ruby-1.9.3-p429/gems/mysql2-0.3.11 for inspection.
    Results logged to /Users/aselder/.rvm/gems/ruby-1.9.3-p429/gems/mysql2-0.3.11/ext/mysql2/gem_make.out

我也尝试了各种命令行选项来获取gem以找到mysql安装:

e.g。        gem install mysql2 - --with-mysql-config = / usr / local / opt / mysql / bin / mysql_config

5 个答案:

答案 0 :(得分:3)

我找到了这个答案,它解决了我的问题: Error installing mysql2: Failed to build gem native extension

引用:

在使用aptitude的Ubuntu / Debian和其他发行版上:

sudo apt-get install libmysql-ruby libmysqlclient-dev

在Red Hat / CentOS和其他使用yum的发行版上:

sudo yum install mysql-devel

在带有自制软件的Mac OS X上:

brew install mysql

我在debian上,在运行上述命令后,我跑了:

gem install mysql2

并且它工作了np。

答案 1 :(得分:1)

我解决了在启动mysql服务器的情况下安装gem的问题!

brew install mysql

mysql.server start

bundle install

在ruby-1.9.3-p125下。

希望这有帮助

答案 2 :(得分:0)

尝试使用Homebrew安装mysql,使用Bundler安装mysql2 gem。

brew update
brew install mysql

将以下内容添加到Gemfile

gem "mysql2"

执行命令

bundle install

答案 3 :(得分:0)

我通过自制软件将mysql从5.6降级到5.5来解决了这个问题。无法提供更详细的解释,但它修复了它。

答案 4 :(得分:0)

我有一个非常愚蠢的解决方案:我打开Xcode并接受了许可协议。更新下载了一个新版本,在手动接受新协议之前我无法编译任何内容。