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

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

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

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

Q&A

1回答

727閲覧

rails sができない、mysqlの問題

kai20000803

総合スコア29

Ruby on Rails

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

0グッド

0クリップ

投稿2020/06/22 10:40

編集2020/06/23 10:04

エラー文

Could not find gem 'rails (~> 5.2.2)' in any of the gem sources listed in your Gemfile. Run `bundle install` to install missing gems.

何をしたのか

rails s をするとこうなりました

このエラー文にあるようにbundle installをすると

The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies....
Using rake 13.0.1
Using concurrent-ruby 1.1.6
Using i18n 1.8.3
Using minitest 5.14.1
Using thread_safe 0.3.6
Using tzinfo 1.2.7
Using activesupport 5.2.4.3
Using builder 3.2.4
Using erubi 1.9.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.9
Using rails-dom-testing 2.0.3
Using crass 1.0.6
Using loofah 2.6.0
Using rails-html-sanitizer 1.3.0
Using actionview 5.2.4.3
Using rack 2.2.3
Using rack-test 1.1.0
Using actionpack 5.2.4.3
Using nio4r 2.5.2
Using websocket-extensions 0.1.5
Using websocket-driver 0.7.2
Using actioncable 5.2.4.3
Using globalid 0.4.2
Using activejob 5.2.4.3
Using mini_mime 1.0.2
Using mail 2.7.1
Using actionmailer 5.2.4.3
Using activemodel 5.2.4.3
Using arel 9.0.0
Using activerecord 5.2.4.3
Using mimemagic 0.3.5
Using marcel 0.3.3
Using activestorage 5.2.4.3
Using bindex 0.8.1
Using msgpack 1.3.3
Using bootsnap 1.4.6
Using bundler 2.1.4
Using byebug 11.1.3
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using coffee-script 2.4.1
Using method_source 1.0.0
Using thor 1.0.1
Using railties 5.2.4.3
Using coffee-rails 4.2.2
Using ffi 1.13.1
Using jbuilder 2.10.0
Using rb-fsevent 0.10.4
Using rb-inotify 0.10.1
Using ruby_dep 1.5.0
Using listen 3.1.5
Fetching mysql2 0.5.3
Installing mysql2 0.5.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/mysql2-0.5.3/ext/mysql2

/home/ec2-user/.rvm/rubies/ruby-2.6.3/bin/ruby -I
/home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0 -r
./siteconf20200623-6737-azqw8f.rb extconf.rb
--with-ldflags=-L/usr/local/opt/openssl/lib
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes

Using mysql_config at /usr/bin/mysql_config

checking for mysql.h... no
checking for mysql/mysql.h... no

mysql.h is missing. You may need to 'sudo apt-get install libmariadb-dev', 'sudo apt-get
install libmysqlclient-dev' or 'sudo yum install mysql-devel', 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
--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=/home/ec2-user/.rvm/rubies/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
--without-mysql-config

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

/home/ec2-user/.rvm/gems/ruby-2.6.3/extensions/x86_64-linux/2.6.0/mysql2-0.5.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/mysql2-0.5.3
for inspection.
Results logged to
/home/ec2-user/.rvm/gems/ruby-2.6.3/extensions/x86_64-linux/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
となってしまいます
初心者なので対処法がわかりません
お願いします

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

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

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

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

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

raccy

2020/06/22 13:22

まず試すことは英語のメッセージに書いてある通りなのですが、英語が読めないって事でしょうか?
kai20000803

2020/06/23 08:17

これに従い、bundle installをすると 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 こうなります 調べても対処法がわかりません。メンタでエンジニアと契約したんですがその方がわからないと言われて困っています
raccy

2020/06/23 09:45

その「bundle installしたらどうなったのか」を質問に追記してください。今の質問の内容では「bundle installをしてみてください」とだけしか回答できません。どのように考え、何をして、どのようなエラーにぶつかったのか、そういったことを全て書いて始めて、あと何ができるのか、どのような解決方法が考えられるかがわかります。
kai20000803

2020/06/23 09:55

追記しました よければ この質問への回答も欲しいです
raccy

2020/06/23 09:56

表示されるメッセージはそれだけだったでしょうか?エラーメッセージは最後だけではなく、その前にも解決のためのヒントが現れている場合があります。もし、省略しているのであれば、全文を載せるようにしてください。
guest

回答1

0

エラーメッセージで注目すべきはこの文です。

checking for mysql.h... no checking for mysql/mysql.h... no mysql.h is missing. You may need to 'sudo apt-get install libmariadb-dev', 'sudo apt-get install libmysqlclient-dev' or 'sudo yum install mysql-devel', and try again.

mysql.hというのはmysqlのライブラリのヘッダで、Rubyのmysql2パッケージをコンパイルするために必要なファイルです。そのファイルが見つからないとなっていますので、mysql.hがインストールされていない、または、見つけられないかの何れかです。

mysql.hをインストールする方法は、メッセージにあるとおりsudo apt-get install libmariadb-dev等を実行することで可能です。ただ、このインストール方法はOSやそのバージョンによって異なっており、Debian系ならapt-getまたはaptを使う、RHEL系ならyumまたはdnfを使うという違いもありますし、また、パッケージ名自体も(同じOSでもメジャーバージョンが違うだけで)違う場合があります。何を入れたら良いのか分からない場合は、取りあえず書かれたコマンドを試して見るか、検索してみてください。それでも分からない場合は、OS名(およびバージョン)を明記の上、mysqlのライブラリのヘッダであるmysql.hのインストール方法を聞いてみてください。

なお、RailsはGemfile記載の全てのパッケージとその依存関係にあるパッケージが正常にインストールされない限り動作はしません。bundle installがエラーなく完了できるようになるまでは、動かない物だと思ってください。

投稿2020/06/23 10:26

raccy

総合スコア21735

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

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

kai20000803

2020/06/23 12:15

Loaded plugins: priorities, update-motd, upgrade-helper 1073 packages excluded due to repository priority protections Resolving Dependencies --> Running transaction check ---> Package mysql-devel.noarch 0:5.5-1.6.amzn1 will be installed --> Processing Dependency: mysql55-devel >= 5.5 for package: mysql-devel-5.5-1.6.amzn1.noarch --> Running transaction check ---> Package mysql55-devel.x86_64 0:5.5.62-1.23.amzn1 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================== Package Arch Version Repository Size ======================================================================================== Installing: mysql-devel noarch 5.5-1.6.amzn1 amzn-main 2.7 k Installing for dependencies: mysql55-devel x86_64 5.5.62-1.23.amzn1 amzn-updates 201 k Transaction Summary ======================================================================================== Install 1 Package (+1 Dependent package) Total download size: 204 k Installed size: 602 k Is this ok [y/d/N]: 三つ目を入力するとこうなったんですが ググっても出てこないんですが、これはどういうことなんですか? mysqlがインストールされている気がしないんですが
kai20000803

2020/06/23 12:33

macos catalina バージョン10.15.5です
raccy

2020/06/23 12:41

メッセージから推測すると、実際に動作させているのはAWSではないですか?私はAWSの環境をもっていい無いので詳しいことは分かりません。回答にもあるとおり、OSによってやり方は異なってくるので、知らない環境は確実なことは言えないからです。 今の質問にやったことを追記するか、別質問にするかして、他の人の回答を待ってみるしか無いと思います。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問