【问题标题】:Mysql2 gem installation issue and bundle install failedMysql2 gem 安装问题和捆绑安装失败
【发布时间】:2019-10-24 11:32:13
【问题描述】:

我正在尝试运行捆绑安装。我的环境是 Mojave,当前 ruby​​ 版本安装为 2.3.7,由于终端出现以下错误,我无法进行捆绑安装。谁能告诉我为什么会失败。

我也尝试过捆绑更新。没有什么对我有用。

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/efutures/Documents/vhosts/Actionrev-average-costing/.bundle/ruby/2.3.0/gems/mysql2-0.4.10/ext/mysql2
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -I /Library/Ruby/Site/2.3.0 -r ./siteconf20191024-23547-w2j56k.rb extconf.rb --with-ldflags\=-L/usr/local/opt/openssl/lib\
--with-cppflags\=-I/usr/local/opt/openssl/include
checking for rb_absint_size()... *** 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/2.3/usr/bin/$(RUBY_BASE_NAME)
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:535:in `block in try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/tmpdir.rb:89:in `mktmpdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:532:in `try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:556:in `try_link'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:765:in `try_func'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:1051:in `block in have_func'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:942:in `block in checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:350:in `block (2 levels) in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:320:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:350:in `block in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:320:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:346:in `postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:941:in `checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:1050:in `have_func'
    from extconf.rb:26:in `<main>'

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

  /Users/efutures/Documents/vhosts/Actionrev-average-costing/.bundle/ruby/2.3.0/extensions/universal-darwin-18/2.3.0/mysql2-0.4.10/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/efutures/Documents/vhosts/Actionrev-average-costing/.bundle/ruby/2.3.0/gems/mysql2-0.4.10 for inspection.
Results logged to /Users/efutures/Documents/vhosts/Actionrev-average-costing/.bundle/ruby/2.3.0/extensions/universal-darwin-18/2.3.0/mysql2-0.4.10/gem_make.out

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

【问题讨论】:

  • 根据You have to install development tools first,问题可能是您缺少 MySQL 开发工具(我以前在 linux 上遇到过的东西)。我不知道如何在 mac 上安装它们,但这可能会为您在互联网上提供更多搜索选项。

标签: ruby-on-rails ruby mysql2


【解决方案1】:

首先在终端运行以下,

并提供以下内容,

locate mysql_config

提供的,/usr/bin/mysql_config

现在运行,

sudo gem install mysql -- --with-mysql-config=/usr/bin/mysql_config

【讨论】:

  • 好的,使用“locate”命令我得到以下输出,我无法再进一步了。 ========================================== 警告:定位数据库(/var/ db/locate.database) 不存在。要创建数据库,请运行以下命令: sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist 请注意,生成数据库可能需要一些时间;创建数据库后,此消息将不再出现。
  • 你有什么想法吗?
  • 不,我不知道,但是请检查您是否可以使用mysql -u root -p正确登录
  • 不,我不能。让我先解决这个问题。
猜你喜欢
  • 2015-11-29
  • 2018-12-02
  • 1970-01-01
  • 2019-11-09
  • 1970-01-01
  • 2011-05-06
  • 1970-01-01
  • 2017-03-11
相关资源
最近更新 更多