Rails command line not working because of rdoc

Hello, I am newbie in both ruby and rails.

I am unable to open rails console. When I run ‘rails console’, it shows this error.

/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:15:in `require': cannot load such file -- rdoc (LoadError)

I googled it and found that I have to add rdoc in gem file, so I added gem 'rdoc', '~>4.2.2' in my gemfile and done bundle install

But now I am receiving different error with JSON and rails server is also not working

/home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/json-1.8.6/lib/json/common.rb:155:in `initialize': wrong number of arguments (given 2, expected 1) (ArgumentError)

So I googled it again and understood that the syntax is changed for latest rub versions and rdoc uses JSON version 1.4 which is for old ruby.

What should I do? Am I doing something wrong? Help me to solve this issue.

Thank you!

My system: Linux – Fedora 35 Ruby version : ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]

Our own Rails 7 app’s Gemfile does not have rdoc and it runs fine. When generating a new Rails 7 app, rdoc is not present. Which Rails version do you use? Where is rdoc loaded from? The first error you show points to bootsnap which is the code preloading mechanism. If you temporarily disable bootsnap in config/boot.rb, maybe you will see the stack trace with where rdoc is loaded from.

Same error is happening!

When bootsnap disabled:

/home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/irb-1.4.1/lib/irb/input-method.rb:17:in `require': cannot load such file -- rdoc (LoadError)
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/irb-1.4.1/lib/irb/input-method.rb:17:in `<top (required)>'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/irb-1.4.1/lib/irb/context.rb:14:in `require_relative'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/irb-1.4.1/lib/irb/context.rb:14:in `<top (required)>'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/irb-1.4.1/lib/irb.rb:16:in `require_relative'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/irb-1.4.1/lib/irb.rb:16:in `<top (required)>'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/commands/console/console_command.rb:3:in `require'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/commands/console/console_command.rb:3:in `<top (required)>'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command/behavior.rb:44:in `require'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command/behavior.rb:44:in `block (2 levels) in lookup'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command/behavior.rb:40:in `each'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command/behavior.rb:40:in `block in lookup'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command/behavior.rb:39:in `each'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command/behavior.rb:39:in `lookup'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command.rb:73:in `find_by_namespace'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command.rb:46:in `invoke'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/commands.rb:18:in `<top (required)>'
	from bin/rails:4:in `require'
	from bin/rails:4:in `<main>'

When bootsnap enabled:

/home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:15:in `require': cannot load such file -- rdoc (LoadError)
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:15:in `require'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/irb-1.4.1/lib/irb/input-method.rb:17:in `<main>'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/irb-1.4.1/lib/irb/context.rb:14:in `require_relative'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/irb-1.4.1/lib/irb/context.rb:14:in `<main>'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/irb-1.4.1/lib/irb.rb:16:in `require_relative'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/irb-1.4.1/lib/irb.rb:16:in `<main>'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/commands/console/console_command.rb:3:in `<main>'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command/behavior.rb:44:in `block (2 levels) in lookup'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command/behavior.rb:40:in `each'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command/behavior.rb:40:in `block in lookup'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command/behavior.rb:39:in `each'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command/behavior.rb:39:in `lookup'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command.rb:73:in `find_by_namespace'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command.rb:46:in `invoke'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/commands.rb:18:in `<main>'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from /home/suryasiva/projects/Triaxial/triaxial/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from bin/rails:4:in `<main>'

@sdubois can you use rails console? Could you share your gem file? Please

You could start from a fresh Rails app using the latest version and see how it goes:

Actually @sdubois at the time I asked this question I was following that article. This problem is raised at step 6.3 where we use console to create new articles

Indeed it seems irb requires rdoc now. But my understanding is the rdoc binary should be made available as part of the Ruby installation and there should not be a need to add it to the Gemfile (NB: I am not an experienced rubyist). This at least seems to be the case in the latest Ruby installed on my machine (3.1.1).

So you could update to the latest Ruby 3.1.1 in case issues come from there. It should update the standard rdoc library to 6.4.0. Then I guess you can remove rdoc from the Gemfile and try again. https://www.ruby-lang.org/en/news/2021/12/25/ruby-3-1-0-released/

I’m having the same problem with trying to run the rails console. I’ve been using Ruby on Rails for a few years and I just decided to install a new hard disk drive in my Rails Server and also load the latest version of everything. I originally had my Server running Red Had Fedora 19. This time I decided to go a little more professional and now I have loaded it with Rocky 8.5. I’m going through the Rails Guides and Getting Started with Rails. Everything works fine until I get down to Chapter 6.3 and try to start the console. Here are the errors:

Here is my Environment:

The second screenshot shows you are running ruby 3.0.2, I would try upgrading to 3.1.1.

Sebastien, Thanks for helping. I downloaded the 3.1.1 version of ruby and did a source install and when I do a ruby -v is shows: ruby 3.1.1p18. I removed the “blog” folder from my “home/workspace” folder and then from my workspace folder I did a “rails new blog” and I ran the Server and went to the page on my browser, but down in the bottom is says that I running version 3.0.2 of ruby. I looked in the Gemfile and yes it says ruby “3.0.2” so I changed it to the correct 3.1.1, but now when I try to run the Server I get the error message: Your Ruby version is 3.0.2, but your Gemfile specified 3.1.1. So how do I get rid of the old 3.0.2 version of Ruby? And why does ruby -v show the new version, but Rails thinks I’m still using 3.0.2?

If you got Ruby 3.0.2 in your Gemfile when doing rails new, I would guess it means your system environment still points to Ruby 3.0.2. You could add something like export PATH=<path to ruby 3.1.1>:$PATH in your shell profile. Or if you installed the latest Ruby with something like rvm, it would be rvm global 3.1.1. If there is still a Ruby 3.0.2 installed on the system you might also try uninstalling it altogether. Just some thoughts.

Sebastien, Again, thanks for the thoughts. I am going to start from scratch installing everything on this Server again. I don’t use a version manager like rvm. I tried using one a few years ago and it got my system all messed up. I am now reinstalling the Rocky 8.5. I will make sure Ruby 3.1.1 is installed before I install Rails this time and that there is no ruby 3.0.2 anywhere.

I’d really recommend you give rvm or rbenv or chruby or really anything besides system ruby another try. At some point, you are going to need it, because you’re going to want to update your Rails app to use a newer version of Ruby. System installs are very limiting.

Further, a good version manager (by which I mean one you understand and use correctly) will also do such helpful things as swizzle your path, so subcommands like rdoc are not fired into the void. When you call one of those shell methods, you will get the appropriate version of that method, one bound to the version of Ruby you’re actually using in the current contest.

Walter

Walter, Thanks for the suggestions. I had a bad experience with rbenv a few years ago, but I will now try one of the other version managers.