簡體   English   中英

在 Mojave 上使用 MySQL2 安裝 Rails 失敗

[英]Rails installation with MySQL2 failing on Mojave

OS: Mojave 10.14.2
Ruby v 2.6.0
Rails v 2.5.2
Mysql 8 Server (installed standalone, not through homebrew, and tested through phpmyadmin)

在我的 Gemfile 中,我有:

gem 'mysql2', '>= 0.4.4', '< 0.6.0'

我做了:

bundle config build.mysql2 --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
bundle install --path .bundle

我收到以下錯誤消息:

Fetching mysql2 0.5.2
Installing mysql2 0.5.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/test_guy/Dropbox/Development/Rails/TestAppMac/.bundle/ruby/2.6.0/gems/mysql2-0.5.2/ext/mysql2
/Users/test_guy/.rbenv/versions/2.6.0/bin/ruby -I /Users/test_guy/.rbenv/versions/2.6.0/lib/ruby/2.6.0 -r ./siteconf20190128-82406-1b5c8qc.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=/Users/test_guy/.rbenv/versions/2.6.0/bin/$(RUBY_BASE_NAME)
/Users/test_guy/.rbenv/versions/2.6.0/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/test_guy/.rbenv/versions/2.6.0/lib/ruby/2.6.0/mkmf.rb:552:in `try_link0'
    from /Users/test_guy/.rbenv/versions/2.6.0/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
    from /Users/test_guy/.rbenv/versions/2.6.0/lib/ruby/2.6.0/mkmf.rb:782:in `try_func'
    from /Users/test_guy/.rbenv/versions/2.6.0/lib/ruby/2.6.0/mkmf.rb:1069:in `block in have_func'
    from /Users/test_guy/.rbenv/versions/2.6.0/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
    from /Users/test_guy/.rbenv/versions/2.6.0/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /Users/test_guy/.rbenv/versions/2.6.0/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /Users/test_guy/.rbenv/versions/2.6.0/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
    from /Users/test_guy/.rbenv/versions/2.6.0/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /Users/test_guy/.rbenv/versions/2.6.0/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
    from /Users/test_guy/.rbenv/versions/2.6.0/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
    from /Users/test_guy/.rbenv/versions/2.6.0/lib/ruby/2.6.0/mkmf.rb:1068:in `have_func'
    from extconf.rb:25:in `<main>'

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

  /Users/test_guy/Dropbox/Development/Rails/TestAppMac/.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/test_guy/Dropbox/Development/Rails/TestAppMac/.bundle/ruby/2.6.0/gems/mysql2-0.5.2 for inspection.
Results logged to /Users/test_guy/Dropbox/Development/Rails/TestAppMac/.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.

In Gemfile:
  mysql2

有任何想法嗎?

確保你有命令行開發工具

xcode-select --install

確保通過 Homebrew 在 Mac 上安裝了 openssl。

brew install openssl

使用選項安裝 mysql2 gem。

gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

參考: 在 MacOS Mojave 上安裝 mysql2

如果您的 MySQL 已安裝並正在運行,則運行此命令

gem update --system

之后嘗試

bundle install

這應該可以解決您的問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM