Rails

【Gem::GemNotFoundException】Gemfileを見直すことで解消

01/10/2023

GemNotFoundExceptionが起きたときの対処方法を記載しています。
UnsplashMarkus Spiskeが撮影した写真

先日遭遇したエラーについての覚書です。

Gem::GemNotFoundException

Railsを実行しようとしたところ、エラー【Gem::GemNotFoundException】が発生しました。

% rails s

% /Users/xxxxxxxxxxx/.rbenv/versions/3.2.2/lib/ruby/site_ruby/3.2.0/rubygems.rb:264:in `find_spec_for_exe': can't find gem railties (>= 0.a) with executable rails (Gem::GemNotFoundException)

% bundle exec rails -v

bundler: failed to load command: rails (/Users/xxxxxxxxxx/.rbenv/versions/3.2.2/bin/rails)

/Users/xxxxxxxxxx/src/github.com/xxxxxxxxx/memo_app/vendor/bundle/ruby/3.2.0/gems/bundler-2.3.14/lib/bundler/rubygems_integration.rb:319:in `block in replace_bin_path': can't find executable rails for gem railties. railties is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)

エラー内容からrailsを実行するためのgemが含まれていないことがわかります。

Gemfileに gem "rails"を追記後、bundle install。解消しました。

% rails s
=> Booting Puma
=> Rails 7.0.8 application starting in development
=> Run `bin/rails server --help` for more startup options

-Rails