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

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

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

Cloud9は、クラウドからのプログラミングが可能になるWebサービス。IDEとしての機能が搭載されており、GitHubやHerokuなど他ツールとの連携も可能です。ブラウザ上で動くため、デバイスに関係なく開発環境を準備できます。

Ruby on Rails

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

Q&A

解決済

1回答

480閲覧

ruby on railsバージョンをアップデートしたいが、mysqlのエラーが発生します。

Java_student

総合スコア62

Cloud9

Cloud9は、クラウドからのプログラミングが可能になるWebサービス。IDEとしての機能が搭載されており、GitHubやHerokuなど他ツールとの連携も可能です。ブラウザ上で動くため、デバイスに関係なく開発環境を準備できます。

Ruby on Rails

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

0グッド

0クリップ

投稿2023/11/28 04:14

編集2023/11/30 05:12

実現したいこと

下記の質問によって、環境を作り直して、プロジェクトを移行してGemfileに記述してあるrubyとrailsのバージョンをアップさせようとしたのですが、mysql2に関してのエラーが発生しました。

nodeのバージョンアップをしたいです

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

・bundle updateを行ったところ

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /home/ubuntu/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5/ext/mysql2 /home/ubuntu/.rvm/rubies/ruby-3.2.2/bin/ruby extconf.rb checking for rb_absint_size()... yes checking for rb_absint_singlebit_p()... yes checking for rb_gc_mark_movable()... yes checking for rb_wait_for_single_fd()... yes checking for rb_enc_interned_str() in ruby.h... yes *** 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/ubuntu/.rvm/rubies/ruby-3.2.2/bin/$(RUBY_BASE_NAME) --with-openssl-dir --without-openssl-dir --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 --with-mysqlclient-dir --without-mysqlclient-dir --with-mysqlclient-include --without-mysqlclient-include=${mysqlclient-dir}/include --with-mysqlclient-lib --without-mysqlclient-lib=${mysqlclient-dir}/lib --with-mysqlclientlib --without-mysqlclientlib /home/ubuntu/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/mkmf.rb:1083:in `block in find_library': undefined method `split' for nil:NilClass (NoMethodError) paths = paths.flat_map {|path| path.split(File::PATH_SEPARATOR)} ^^^^^^ from /home/ubuntu/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/mkmf.rb:1083:in `each' from /home/ubuntu/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/mkmf.rb:1083:in `flat_map' from /home/ubuntu/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/mkmf.rb:1083:in `find_library' from extconf.rb:131:in `<main>' To see why this extension failed to compile, please check the mkmf.log which can be found here: /home/ubuntu/.rvm/gems/ruby-3.2.2/extensions/x86_64-linux/3.2.0/mysql2-0.5.5/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /home/ubuntu/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5 for inspection. Results logged to /home/ubuntu/.rvm/gems/ruby-3.2.2/extensions/x86_64-linux/3.2.0/mysql2-0.5.5/gem_make.out An error occurred while installing mysql2 (0.5.5), and Bundler cannot continue. Make sure that `gem install mysql2 -v '0.5.5' --source 'https://rubygems.org/'` succeeds before bundling. In Gemfile: mysql2 ubuntu:~/environment/tsunageru (master) $ gem install mysql2 -v '0.5.5' --source 'https://rubygems.org/' Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. current directory: /home/ubuntu/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5/ext/mysql2 /home/ubuntu/.rvm/rubies/ruby-3.2.2/bin/ruby extconf.rb checking for rb_absint_size()... yes checking for rb_absint_singlebit_p()... yes checking for rb_gc_mark_movable()... yes checking for rb_wait_for_single_fd()... yes checking for rb_enc_interned_str() in ruby.h... yes *** 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/ubuntu/.rvm/rubies/ruby-3.2.2/bin/$(RUBY_BASE_NAME) --with-openssl-dir --without-openssl-dir --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 --with-mysqlclient-dir --without-mysqlclient-dir --with-mysqlclient-include --without-mysqlclient-include=${mysqlclient-dir}/include --with-mysqlclient-lib --without-mysqlclient-lib=${mysqlclient-dir}/lib --with-mysqlclientlib --without-mysqlclientlib /home/ubuntu/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/mkmf.rb:1083:in `block in find_library': undefined method `split' for nil:NilClass (NoMethodError) paths = paths.flat_map {|path| path.split(File::PATH_SEPARATOR)} ^^^^^^ from /home/ubuntu/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/mkmf.rb:1083:in `each' from /home/ubuntu/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/mkmf.rb:1083:in `flat_map' from /home/ubuntu/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/mkmf.rb:1083:in `find_library' from extconf.rb:131:in `<main>' To see why this extension failed to compile, please check the mkmf.log which can be found here: /home/ubuntu/.rvm/gems/ruby-3.2.2/extensions/x86_64-linux/3.2.0/mysql2-0.5.5/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /home/ubuntu/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5 for inspection. Results logged to /home/ubuntu/.rvm/gems/ruby-3.2.2/extensions/x86_64-linux/3.2.0/mysql2-0.5.5/gem_make.out

該当のソースコード

Gemfile

1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '3.2.2' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' 7gem "rails", "~> 7.1.2" 8# Use mysql as the database for Active Record 9gem "mysql2", "~> 0.5" 10# Use Puma as the app server 11gem 'puma', '~> 5.0' 12# Use SCSS for stylesheets 13gem 'sass-rails', '>= 6' 14# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker 15gem 'webpacker', '~> 5.0' 16# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 17gem 'turbolinks', '~> 5' 18# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 19gem 'jbuilder', '~> 2.7' 20# Use Redis adapter to run Action Cable in production 21# gem 'redis', '~> 4.0' 22# Use Active Model has_secure_password 23# gem 'bcrypt', '~> 3.1.7' 24 25# Reduces boot times through caching; required in config/boot.rb 26gem 'bootsnap', '>= 1.4.4', require: false 27 28group :development, :test do 29 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 30 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 31end 32 33group :development do 34 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 35 gem 'web-console', '>= 4.1.0' 36 # Display performance information such as SQL time and flame graphs for each request in your browser. 37 # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md 38 #gem 'rack-mini-profiler', '~> 2.0' 39 gem 'listen', '~> 3.3' 40 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 41 gem 'spring' 42 43 gem 'better_errors' 44 gem 'binding_of_caller' 45 gem 'letter_opener_web' 46end 47 48# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 49gem 'pagy' 50gem 'carrierwave', '~> 1.3', '>= 1.3.1' 51gem 'mini_magick' 52gem 'ransack' 53gem 'devise' 54#gem 'pry-rails' 55 56#削除機能 57gem "paranoia" 58 59#devise日本語化 60gem 'devise-i18n' 61gem 'rails-i18n' 62 63gem 'net-smtp' 64gem 'net-imap' 65gem 'net-pop' 66 67#お問い合わせ 68gem "dotenv-rails" 69 70gem 'kaminari' 71gem 'bootstrap5-kaminari-views', '~> 0.0.1' 72gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 73group :production do 74 gem 'pg', '>= 0.18', '< 2.0' 75end 76gem 'cloudinary', '~> 1.25.0'

試したこと

エラーログからgem install mysql2 -v '0.5.5' --source 'https://rubygems.org/'の実行を推奨されていたので、実行したところ、何らかの理由で実行できず、 詳細については、mkmf.log ファイルを確認してくださいと表示されました。
mkmf.logを確認中です。

mkmf.logを確認したところ、下記の表示がされました。
!追記!

ubuntu:~/environment/******** (master) $ more /home/ubuntu/.rvm/gems/ruby-3.2.2/extensions/x86_64-linux/3.2.0/mysql2-0.5.5/mkmf.log have_func: checking for rb_absint_size()... -------------------- yes LD_LIBRARY_PATH=.:/home/ubuntu/.rvm/rubies/ruby-3.2.2/lib "gcc -o conftest -I/home/ubuntu/.rvm/rubies/ruby-3.2.2/include/ruby-3.2.0/x86_64-linux -I/ home/ubuntu/.rvm/rubies/ruby-3.2.2/include/ruby-3.2.0/ruby/backward -I/home/ubuntu/.rvm/rubies/ruby-3.2.2/include/ruby-3.2.0 -I. -O3 -fno-fast-ma th -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdiv-by-zero -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indent ation -Wpointer-arith -Wwrite-strings -Wold-style-definition -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logic --More--(4%)

!追記!
mysql2だけをコメントアウトして、bundle updateを実行したところ、エラーなくupdateされました。
問題はmysql2だけでした。

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

ruby3
rails7
Ubuntu 22.04.3

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

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

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

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

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

guest

回答1

0

自己解決

bundle install前に
sudo apt install -y libmysqlclient-dev
したところ現状ではエラーが消えた。

投稿2023/12/03 00:15

Java_student

総合スコア62

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.41%

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

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

質問する

関連した質問