ruby-on-rails - 尽管使用 `gem install...` 命令进行安装,但 mysql2 gem 在捆绑安装时失败

标签 ruby-on-rails ruby rubygems mysql2

这是我的日志 bundle install

Fetching mysql2 0.5.2
Installing mysql2 0.5.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
...
...
...
Cannot find mysql_config at /usr/local/opt/mysql@5.6/bin/mysql_config
--with-ldflags=-L/usr/local/opt/openssl/lib
--with-cppflags=-I/usr/local/opt/openssl/include
-----
*** 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=/Users/admin/.asdf/installs/ruby/2.6.3/bin/$(RUBY_BASE_NAME)
    --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-mysql-config

To see why this extension failed to compile, please check the mkmf.log which can be found
here:

/Users/admin/development/locari/vendor/bundle/ruby/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/Users/admin/development/locari/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.2 for
inspection.
Results logged to
/Users/admin/development/locari/vendor/bundle/ruby/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/gem_make.out

An error occurred while installing mysql2 (0.5.2), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'` succeeds
before bundling.

所以我按照它说的去做,然后运行 ​​sudo gem install mysql2 -v '0.5.2' --source
$ sudo gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'
Building native extensions. This could take a while...
Successfully installed mysql2-0.5.2
Parsing documentation for mysql2-0.5.2
Done installing documentation for mysql2 after 0 seconds
1 gem installed

它安装得很好!但是当我运行 bundle install再次,我得到同样的错误。我试过卸载、取消链接和重新安装 mysql在酿造中。

我接下来可以尝试什么??

最佳答案

首先运行这些命令:bundle config --local build.mysql2 "--with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib"然后运行 ​​bundle install有用。

关于ruby-on-rails - 尽管使用 `gem install...` 命令进行安装,但 mysql2 gem 在捆绑安装时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56786993/

相关文章:

ruby - google-api-client gem 的 API

ruby - 从本地 .gem 文件安装 'ferret' gem 时,Errno::EEXIST 文件存在错误

ruby-on-rails - 在 docker 上安装 gem

javascript - 使用 javascript 跟踪链接

php - 在表单中嵌套模型关系 - Laravel

ruby-on-rails - Tire gem:如何访问Elasticsearch的 'highlight'属性?

ruby-on-rails - 通过 JSON 调用创建 Devise 用户

ruby - Ruby 生态系统中 Semver 的替代方案

ruby - 如何用数组编码哈希?

macos - 安装后找不到 compass 命令