Ruby on Rails: Fixing cannot load such file -- rails/cli (LoadError)
Ruby on Rails: Fixing cannot load such file -- rails/cli (LoadError)
Error
Rails doesn’t work. We get a require: cannot load such file -- rails/cli (LoadError)
1
2
3
4
5
6
7
8
9
> rails
<internal:/usr/share/rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require': cannot load such file -- rails/cli (LoadError)
from <internal:/usr/share/rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
from /usr/share/rvm/gems/ruby-3.2.2/gems/railties-7.2.2.2/exe/rails:10:in `<top (required)>'
from /usr/share/rvm/gems/ruby-3.2.2/bin/rails:25:in `load'
from /usr/share/rvm/gems/ruby-3.2.2/bin/rails:25:in `<main>'
from /usr/share/rvm/gems/ruby-3.2.2/bin/ruby_executable_hooks:22:in `eval'
from /usr/share/rvm/gems/ruby-3.2.2/bin/ruby_executable_hooks:22:in `<main>'
Fix
Option 1: Using the right rvm version
1
2
rvm list
rvm use ruby version
Option 2: Bundle install
Remove the Gemfile.lock and install all of the gems again.
1
2
rm Gemfile.lock
bundle
Result
Rails works again.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
> rails
Usage:
bin/rails COMMAND [options]
You must specify a command. The most common commands are:
generate Generate new code (short-cut alias: "g")
console Start the Rails console (short-cut alias: "c")
server Start the Rails server (short-cut alias: "s")
test Run tests except system tests (short-cut alias: "t")
test:system Run system tests
dbconsole Start a console for the database specified in config/database.yml
(short-cut alias: "db")
plugin new Create a new Rails railtie or engine
All commands can be run with -h (or --help) for more information.
Sources
This post is licensed under CC BY-NC 4.0 by the author.