質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

2回答

948閲覧

macでrails環境構築中にmysql2がインストールできない

hakata-monge

総合スコア0

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2021/04/05 06:08

前提・実現したいこと

初めて質問させていただきます。情報の不足ないように記載するつもりですが、何か至らない点があればご指摘いただけるとたすかります。
macでrailsの環境構築中です。bunlde install を実施してもmysq2がインストールできずに進まない状況です。
似たような事象が起きている記事を、本サイトも含めて色々と試しましたが、解決できていません。
本当に困っています。何かご助言いただけると幸いです。

発生している問題・エラーメッセージ

rails new で作ったsample_appディレクトリ でbundle installを実施してもエラー
rails sもできない。

該当のソースコード

使用言語:Ruby

USERnoMacBook-Pro:sample_app user$ sudo bundle install
Password:
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
Fetching gem metadata from https://rubygems.org/............
Resolving dependencies.....
Using rake 13.0.3
Using concurrent-ruby 1.1.8
Using erubi 1.10.0
Using thread_safe 0.3.6
Using minitest 5.14.4
Using racc 1.5.2
Using crass 1.0.6
Using rack 2.2.3
Using nio4r 2.5.7
Using websocket-extensions 0.1.5
Using mini_mime 1.1.0
Using arel 9.0.0
Using marcel 1.0.1
Using public_suffix 4.0.6
Using io-like 0.3.1
Using bindex 0.8.1
Using msgpack 1.4.2
Using bundler 2.2.15
Using byebug 11.1.3
Using regexp_parser 2.1.1
Using childprocess 3.0.0
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using method_source 1.0.0
Using thor 1.1.0
Using ffi 1.15.0
Using rb-fsevent 0.10.4
Using ruby_dep 1.5.0
Using puma 3.12.6
Using tilt 2.0.10
Using spring 2.1.1
Using turbolinks-source 5.2.0
Using i18n 1.8.10
Using tzinfo 1.2.9
Using rubyzip 2.3.0
Using nokogiri 1.11.2 (arm64-darwin)
Using rack-test 1.1.0
Using websocket-driver 0.7.3
Using nokogiri 1.11.2 (x86_64-darwin)
Using addressable 2.7.0
Fetching mysql2 0.5.3
Using builder 3.2.4
Using archive-zip 0.12.0
Using bootsnap 1.7.3
Using coffee-script 2.4.1
Using rb-inotify 0.10.1
Using sprockets 3.7.2
Using uglifier 4.2.0
Using turbolinks 5.2.1
Using activesupport 5.2.5
Using selenium-webdriver 3.142.7
Using loofah 2.9.0
Using xpath 3.2.0
Using mail 2.7.1
Using rails-dom-testing 2.0.3
Using activemodel 5.2.5
Using globalid 0.4.2
Using rails-html-sanitizer 1.3.0
Using capybara 3.35.3
Using listen 3.1.5
Using sass-listen 4.0.0
Using actionview 5.2.5
Using jbuilder 2.11.2
Using chromedriver-helper 2.1.1
Using activejob 5.2.5
Using activerecord 5.2.5
Using spring-watcher-listen 2.0.1
Using sass 3.7.4
Using actionpack 5.2.5
Using activestorage 5.2.5
Using railties 5.2.5
Using actionmailer 5.2.5
Using sprockets-rails 3.2.2
Using actioncable 5.2.5
Using coffee-rails 4.2.2
Using sass-rails 5.1.0
Using web-console 3.7.0
Using rails 5.2.5
Installing mysql2 0.5.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/ext/mysql2

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20210405-31769-m7b75d.rb extconf.rb
--with-opt-dir=/usr/local/opt/openssl@1.1
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
--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.6/usr/bin/$(RUBY_BASE_NAME)
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/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 /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in block in try_link0'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in mktmpdir' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in try_link0'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in try_link' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:782:in try_func'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1069:in block in have_func' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in block in checking_for'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in block (2 levels) in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in block in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in checking_for'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/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:

/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/mysql2-0.5.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/mysql2-0.5.3/gem_make.out

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

In Gemfile:
mysql2

試したこと

gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'の実行

mkmf.logの確認
cat /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/mysql2-0.5.3/mkmf.logで見に行く

mkmf.logの中身

"xcrun clang -o conftest -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -I/usr/local/opt/openssl@1.1/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib -L/usr/local/opt/openssl@1.1/lib -L. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/usr/local/lib -arch x86_64 -lruby.2.6 "
In file included from conftest.c:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found #include "ruby/config.h"
^~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: note: did not find header 'config.h' in framework 'ruby' (loaded from '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks')
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char *argv)
4: {
5: return 0;
6: }
/
end */
**
中身は見れるもその後どうするべきかわからず。

補足情報(FW/ツールのバージョンなど)

実行環境
macOS Catalina
ruby 2.6.3
rbenv 1.1.2
$ which ruby
/usr/bin/ruby
gem 3.0.3
Xcode 12.4
Build version 12D4e

$ mysql --version
mysql Ver 8.0.23 for osx10.15 on x86_64 (Homebrew)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

自己解決

opensslに問題があったようです。
下記コマンドを実行したところうまくいきました。

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

投稿2021/04/14 13:36

hakata-monge

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

technocore

2021/04/14 14:06

そんな面倒な手順が必要なのですか。 不思議な環境ですね。
hakata-monge

2021/04/14 14:18

詳しい方に聞いた内容なのですが、macの場合、Apple独自のopensslを使用しており、Homebrewからインストールできるものと異なるため、home brew でインストールしたopenSSHに切り替える必要があるそうです。 ↓の記事も参考になりました。お気遣い頂きありがとうございました。 https://tearoom6.hateblo.jp/entry/2020/05/30/225038
guest

0

rails new のときに -d mysql をつけるのが一番簡単です。
とりあえずおまかせでmysql2をインストールしてくれますので。

【Gemfile】 source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '3.0.0' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' gem 'rails', '~> 6.1.3', '>= 6.1.3.1' # Use mysql as the database for Active Record gem 'mysql2', '~> 0.5' # Use Puma as the app server gem 'puma', '~> 5.0' .......... ..........

投稿2021/04/05 12:33

technocore

総合スコア7225

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問