Rails7でMysqlをデータベースに指定して、アプリを作っています。
rails new ○○○ -d mysql をコマンドプロンプトで実行したときに以下のエラーがでました。
エラー
省略ー--
[14556, #<Thread:0x000002d72be75798 run>, #<NameError: uninitialized constant Gem::Source
(defined?(@source) && @source) || Gem::Source::Installed.new ^^^^^^^^
Did you mean? Gem::SourceList>, ["C:/Ruby/Ruby31-
省略ーー
/friendly_errors.rb:103:in with_friendly_errors'", "C:/Ruby/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bundler-2.3.7/libexec/bundle:36:in
<main>'"]]
C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/bundler/rubygems_ext.rb:18:in `source': uninitialized constant Gem::Source (NameError)
(defined?(@source) && @source) || Gem::Source::Installed.new ^^^^^^^^
Did you mean? Gem::SourceList
from C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/bundler/rubygems_ext.rb:50:in `extension_dir'
省略ー--
internal:C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb:167:in `ensure in require': CRITICAL: RUBYGEMS_ACTIVATION_MONITOR.owned?: before false -> after true (RuntimeError)
省略ー---
C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/bundler/rubygems_ext.rb:18:in `source': uninitialized constant Gem::Source (NameError)
(defined?(@source) && @source) || Gem::Source::Installed.new ^^^^^^^^
Did you mean? Gem::SourceList
from C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/bundler/rubygems_ext.rb:50:in extension_dir' from C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/rubygems/basic_specification.rb:339:in
have_file?'
from C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/rubygems/basic_specification.rb:86:in `contains_requirable_file?'
省略ー---
run bundle binstubs bundler
Could not find gem 'mysql2 (> 0.5)' in locally installed gems.> 0.5)' in locally installed gems.
rails importmap:install
Could not find gem 'mysql2 (
Run bundle install
to install missing gems.
rails turbo:install stimulus:install
Could not find gem 'mysql2 (~> 0.5)' in locally installed gems.
Run bundle install
to install missing gems.
長くなりすみません。
そのご、作成されたフォルダに移動し、bundle installを実行してみたら以下のエラーがでました。
エラー
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies.....
Using rake 13.0.6
Using racc 1.6.0
Using concurrent-ruby 1.1.10
Using minitest 5.16.3
Using builder 3.2.4
Using erubi 1.11.0
Using crass 1.0.6
Using rack 2.2.4
Using nio4r 2.5.8
Using bundler 2.3.7
Using websocket-extensions 0.1.5
Using marcel 1.0.2
Using mini_mime 1.1.2
Using timeout 0.3.0
Using public_suffix 5.0.0
Using bindex 0.8.1
Using msgpack 1.6.0
Using matrix 0.4.2
Using regexp_parser 2.6.0
Using childprocess 4.1.0
Using method_source 1.0.0
Using thor 1.2.1
Using zeitwerk 2.6.1
Using rexml 3.2.5
Using rubyzip 2.3.2
Using websocket 1.2.9
Using i18n 1.12.0
Using tzinfo 2.0.5
Using nokogiri 1.13.9 (x64-mingw-ucrt)
Using rack-test 2.0.2
Fetching mysql2 0.5.4
Using websocket-driver 0.7.5
Using mail 2.7.1
Using net-protocol 0.1.3
Using addressable 2.8.1
Using puma 5.6.5
Using sprockets 4.1.1
Using bootsnap 1.13.0
Using activesupport 7.0.4
Using loofah 2.19.0
Using xpath 3.2.0
Using selenium-webdriver 4.5.0
Using net-imap 0.3.1
Using net-pop 0.1.2
Using net-smtp 0.3.2
Using rails-dom-testing 2.0.3
Using rails-html-sanitizer 1.4.3
Using activemodel 7.0.4
Using globalid 1.0.0
Using capybara 3.37.1
Using webdrivers 5.2.0
Using actionview 7.0.4
Using activejob 7.0.4
Using activerecord 7.0.4
Using actionpack 7.0.4
Using jbuilder 2.11.5
Using actioncable 7.0.4
Using activestorage 7.0.4
Using actionmailer 7.0.4
Using railties 7.0.4
Using sprockets-rails 3.4.2
Using actionmailbox 7.0.4
Using actiontext 7.0.4
Using importmap-rails 1.1.5
Using stimulus-rails 1.1.0
Using turbo-rails 1.3.2
Using web-console 4.2.0
Using rails 7.0.4
Installing mysql2 0.5.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory:
C:/Ruby/Ruby31-x64/lib/ruby/gems/3.1.0/gems/mysql2-0.5.4/ext/mysql2
C:/Ruby/Ruby31-x64/bin/ruby.exe -I C:/Ruby/Ruby31-x64/lib/ruby/3.1.0 -r
./siteconf20221023-9916-ue8zvc.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... 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=C:/Ruby/Ruby31-x64/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
--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
C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1086:in block in find_library': undefined method
split' for nil:NilClass (NoMethodError)
paths = paths.flat_map {|path| path.split(File::PATH_SEPARATOR)} ^^^^^^ from C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1086:in `each' from C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1086:in `flat_map' from C:/Ruby/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1086:in `find_library' from extconf.rb:103:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can
be found here:
C:/Ruby/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/mysql2-0.5.4/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in
省略ー--
An error occurred while installing mysql2 (0.5.4), and Bundler cannot continue.
In Gemfile:
mysql2
自分なりに調べたのですが、opensslのことやそのほかにもいろいろ出てきましたが全くわかりません。
自分でもopensslというものをパソコンにインストールしてみたりしたのですが、よくわかりません。
opensslというものは必要なのでしょうか。
初心者向けにはじめから説明してあるサイトなどを見つけることができなかったので、なにをどうすればいいのかわかりません。
エラー文の中にでているmkmf.logファイルも見てみたのですが、全くわかりません。
なにかファイルが足りないのでしょうか。
実現したいこと
railsアプリでmysqlをデータベースとして設定すること。
Ruby3.1.2 Rails7 os→windows
![guest](/img/icon/icnUserSample.jpg)
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/10/23 21:38
2022/10/24 00:57
2022/10/24 01:39