【发布时间】:2020-06-15 21:43:00
【问题描述】:
我正在尝试启动 rails 控制台(与我之前的问题无关,因为这些是不同的错误),但我终其一生都无法弄清楚如何解决这个问题,或者我什至要解决什么问题做。我正在运行:ruby 2.6.3p62(2019-04-16 修订版 67580)[x86_64-linux]。
我输入 rails 控制台命令并得到以下信息:
ubuntu:~/environment/sample_app(注册)$ rails 控制台
/home/ubuntu/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem': Error loading the 'mysql2' Active Record adapter. Missing a gem it depends on? mysql2 is not part of the bundle. Add it to your Gemfile. (LoadError)
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/mysql2_adapter.rb:6:in `<main>'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/connection_specification.rb:169:in `spec'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1052:in `establish_connection'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/connection_handling.rb:51:in `establish_connection'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/railtie.rb:201:in `block (2 levels) in <class:Railtie>'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:51:in `each'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/base.rb:327:in `<module:ActiveRecord>'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/base.rb:27:in `<main>'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:370:in `active_record_configured?'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:287:in `disconnect_database'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:111:in `preload'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:157:in `serve'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:145:in `block in run'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:139:in `loop'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:139:in `run'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application/boot.rb:19:in `<top (required)>'
from /home/ubuntu/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/ubuntu/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
ubuntu:~/environment/sample_app (sign-up) $ rails console
/home/ubuntu/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem': Error loading the 'mysql2' Active Record adapter. Missing a gem it depends on? mysql2 is not part of the bundle. Add it to your Gemfile. (LoadError)
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/mysql2_adapter.rb:6:in `<main>'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/connection_specification.rb:169:in `spec'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1052:in `establish_connection'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/connection_handling.rb:51:in `establish_connection'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/railtie.rb:201:in `block (2 levels) in <class:Railtie>'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:51:in `each'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/base.rb:327:in `<module:ActiveRecord>'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/base.rb:27:in `<main>'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:370:in `active_record_configured?'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:287:in `disconnect_database'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:111:in `preload'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:157:in `serve'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:145:in `block in run'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:139:in `loop'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:139:in `run'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application/boot.rb:19:in `<top (required)>'
from /home/ubuntu/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/ubuntu/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
更新 这就是我的 gemfile 目前的样子。
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'rails', '6.0.3.1'
gem 'mysql2', '~> 0.3.20'
gem 'image_processing', '1.9.3'
gem 'mini_magick', '4.9.5'
gem 'active_storage_validations', '0.8.9'
gem 'bcrypt', '3.1.13'
gem 'faker', '2.11.0'
gem 'will_paginate', '3.3.0'
gem 'bootstrap-will_paginate', '1.0.0'
gem 'bootstrap-sass', '3.4.1'
gem 'puma', '4.3.5'
gem 'sass-rails', '6.0.0'
gem 'webpacker', '4.2.2'
gem 'turbolinks', '5.2.1'
gem 'jbuilder', '2.10.0'
gem 'bootsnap', '1.4.6', require: false
group :development, :test do
gem 'sqlite3', '1.4.2'
gem 'byebug', '11.1.3', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'web-console', '4.0.2'
gem 'listen', '3.2.1'
gem 'spring', '2.1.0'
gem 'spring-watcher-listen', '2.0.1'
end
group :test do
gem 'capybara', '3.32.2'
gem 'selenium-webdriver', '3.142.7'
gem 'webdrivers', '4.3.0'
gem 'rails-controller-testing', '1.0.4'
gem 'minitest', '5.11.3'
gem 'minitest-reporters', '1.3.8'
gem 'guard', '2.16.2'
gem 'guard-minitest', '2.4.6'
end
group :production do
gem 'pg', '1.2.3'
gem 'aws-sdk-s3', '1.46.0', require: false
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
# Uncomment the following line if you're running Rails
# on a native Windows system:
# gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
我尝试了给出的建议,但现在当我尝试运行“rails 控制台”时,我的错误看起来像这样。捆绑安装工作正常。
ubuntu:~/environment/sample_app (sign-up) $ rails console
/home/ubuntu/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem': Error loading the 'mysql2' Active Record adapter. Missing a gem it depends on? can't activate mysql2 (>= 0.4.4), already activated mysql2-0.3.21. Make sure all dependencies are added to Gemfile. (LoadError)
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/mysql2_adapter.rb:6:in `<main>'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/connection_specification.rb:169:in `spec'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1052:in `establish_connection'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/connection_handling.rb:51:in `establish_connection'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/railtie.rb:201:in `block (2 levels) in <class:Railtie>'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:51:in `each'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.3.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/base.rb:327:in `<module:ActiveRecord>'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/activerecord-6.0.3.1/lib/active_record/base.rb:27:in `<main>'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:370:in `active_record_configured?'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:287:in `disconnect_database'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:111:in `preload'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:157:in `serve'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:145:in `block in run'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:139:in `loop'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application.rb:139:in `run'
from /home/ubuntu/.rvm/gems/ruby-2.6.3/gems/spring-2.1.0/lib/spring/application/boot.rb:19:in `<top (required)>'
from /home/ubuntu/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/ubuntu/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
【问题讨论】:
标签: ruby-on-rails