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

标签 ruby bundler homebrew mysql2

我在我的机器上安装 mysql2 gem 时遇到问题。

我有 OS X 10.8 和最新的 Xcode,并通过 Homebrew 安装了 mySql。所有 ruby 都使用最新的 RVM 安装。

我可以在 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 安装:

例如 gem install mysql2 -- --with-mysql-config=/usr/local/opt/mysql/bin/mysql_config

最佳答案

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

引用:

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

sudo apt-get install libmysql-ruby libmysqlclient-dev

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

sudo yum install mysql-devel

在带有 Homebrew 的 Mac OS X 上:

brew install mysql

我在 debian 上运行上面的命令后,我运行了:

gem install mysql2

它奏效了。

关于ruby - 如何在 Ruby 1.9.3 下安装 mysql2 gem?在 2.0.0 下工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17303195/

相关文章:

ruby-on-rails - 部署到heroku时清理 bundle 程序缓存

c++ - 使用 Ceres 求解器进行 CMake-ing 项目时冲突的 Eigen 依赖项

r - 使用 Homebrew 安装 R

mysql - mysql.server 启动时出现 PID 错误?

ruby - 如何传递方法发送的所有参数

ruby - 如何从数组中删除后跟相同元素的元素

ruby - 从命令行使用 bundler 将 gem 添加到 gemfile

ruby-on-rails - 不要以 root 身份运行 Bundler - Elastic Beanstalk 上的 Rails6

ruby - PDF 阅读器 ruby​​ gem landscape Page

ruby-on-rails - 从 Gemfile 中删除 gem 后要做什么?