LoginSignup
3
0

More than 3 years have passed since last update.

RailsチュートリアルでRuby3.0.0をインストールしたらbundle updateとbundle installができなかったときの解決法

Posted at

あいさつ

知っている人はこんにちは!知らない人ははじめまして!
独学でプログラミングを極める変態中学生のAtieです!
今回は約3日間格闘し続けたエラーの解決法がわかったのでここに記録を残します
これでやっとRailsチュートリアルを進めることができます

結論から言うと...

Rubyの最新版(3.0.0)をインストールしてしまって依存関係が解決できずに動かなかった!
ということのせいで動きませんでした
なのでRailsチュートリアルと同じバージョンのRuby2.6.3をインストールしてGlobalに2.6.3を設定することで動きました!

開発環境

Ruby 3.0.0
Rails 6.0.3.4
Gemfile.lock は削除済み
Gemfileの内容(名前は「Gemfile」ですがRubyのコードで記載されていてわかりやすいようにわざと.rbの拡張子をつけています本番環境では.rbはついていません以下Gemfileを表示するときは.rbを拡張子としてつけています)

Gemfile.rb
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'rails',      '6.0.3'
gem 'puma',       '4.3.6'
gem 'sass-rails', '5.1.0'
gem 'webpacker',  '4.0.7'
gem 'turbolinks', '5.2.0'
gem 'jbuilder',   '2.9.1'
gem 'bootsnap',   '1.4.5', require: false

group :development, :test do
  gem 'sqlite3', '1.4.1'
  gem 'byebug',  '11.0.1', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  gem 'web-console',           '4.0.1'
  gem 'listen',                '3.1.5'
  gem 'spring',                '2.1.0'
  gem 'spring-watcher-listen', '2.0.1'
end

group :test do
  gem 'capybara',           '3.28.0'
  gem 'selenium-webdriver', '3.142.4'
  gem 'webdrivers',         '4.1.2'
end

# Windows ではタイムゾーン情報用の tzinfo-data gem を含める必要があります
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

エラーの内容

まずはbundle installを行うと以下のようなエラーが出てきました

$ bundle install
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
You have requested:
  listen = 3.1.5

The bundle currently has listen locked at 3.3.3.
Try running `bundle update listen`

If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`

エラーの内容は「バージョンがロックされているからbundle updateでアップデートしてね!」という内容です

$ bundle update
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby armv7l-linux-eabihf

    capybara (= 3.28.0) armv7l-linux-eabihf was resolved to 3.28.0, which depends on
      Ruby (>= 2.4.0) armv7l-linux-eabihf

    listen (= 3.1.5) armv7l-linux-eabihf was resolved to 3.1.5, which depends on
      Ruby (>= 2.2.3, ~> 2.2)

    puma (= 4.3.6) armv7l-linux-eabihf was resolved to 4.3.6, which depends on
      Ruby (>= 2.2) armv7l-linux-eabihf

    selenium-webdriver (= 3.142.4) armv7l-linux-eabihf was resolved to 3.142.4, which depends on
      Ruby (>= 2.3) armv7l-linux-eabihf

内容は「競合が発生しているよ!」という内容です

ググってみると依存関係がどうのこうのだと...
あれ?ちょっと待てよRubyのバージョンってRailsチュートリアルのバージョンと一緒なのか?
という疑問が頭の中をよぎりました
そのときにぴーんと来ました!
なのでまずはRailsチュートリアルのRubyのバージョンを調べました
Railsチュートリアルの初期の状態のGemfileは以下のようになっていました

Gemfile.rb
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.3'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster.
# Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a
  # debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console'
  # anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the
  # background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Railsチュートリアルのバージョンが2.6.3で自分の環境が3.0.0...
違いすぎるだろ!!それじゃ動くわけねぇよ!(3.0.0に至ってはメジャーアップデートでそこそこ大幅に改良されてたし... 詳しくはここへ)
そうですバージョンが大幅に違いました
あるあるです
特にLinuxを使っているとプログラムなどを動かそうとしてもライブラリなどのバージョンどうのこうのの依存関係のせいで動かないのがよくあります(自分が使っているFedoraなどは特にそう)

はぁはぁはぁ...疲れた...やっと動く...(フラグじゃないよ\(^o^)/)

ということで動きました!

最後に

今回はかなり解決に時間がかかったエラーでした
今回のことを経験することができそのおかげで一回りはプログラマーとして成長できたと思います
エラーの原因を探したり解決するのもプログラマーの必須スキルであったりします
そして今回は依存関係などのバージョンの大切さを非常に学ぶことができました
もしこの記事が皆さんのエラー解決に少しでも役に立てたら光栄です
最後まで読んでいただきありがとうございました
ではまた次回の記事で!
AtieのTwitter

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0