rails: Rails console fails to start due to LoadError on trying to require irb

Steps to reproduce

Create a new rails project and run rails console or bin/rails console in the project.

Expected behavior

The rails console starts successfully.

Actual behavior

Rails immediately crashes with the following:

/usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': cannot load such file -- irb (LoadError)
Did you mean?  erb
               drb
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:89:in `register'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:44:in `require'
	from /usr/lib/ruby/gems/3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
	from /usr/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/commands/console/console_command.rb:3:in `<main>'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/lib/ruby/gems/3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
	from /usr/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:44:in `block (2 levels) in lookup'
	from /usr/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:40:in `each'
	from /usr/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:40:in `block in lookup'
	from /usr/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:39:in `each'
	from /usr/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:39:in `lookup'
	from /usr/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/command.rb:76:in `find_by_namespace'
	from /usr/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/command.rb:48:in `invoke'
	from /usr/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/commands.rb:18:in `<main>'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/lib/ruby/gems/3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
	from /home/cameron/OtherProjects/mykanban/bin/rails:5:in `<main>'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
	from /usr/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
	from /usr/lib/ruby/gems/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:10:in `block in fork'
	from /usr/lib/ruby/gems/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:10:in `block in fork'
	from /usr/lib/ruby/gems/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:8:in `fork'
	from /usr/lib/ruby/gems/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:8:in `fork'
	from /usr/lib/ruby/gems/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:26:in `fork'
	from /usr/lib/ruby/gems/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:8:in `fork'
	from /usr/lib/ruby/gems/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:26:in `fork'
	from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from -e:1:in `<main>'

System configuration

Any x86-64 Arch Linux install with ruby and ruby-irb installed through pacman, and rails installed globally through gem. Note, it is possible to require irb normally outside of rails. Rails version: Rails 6.1.3.2 Ruby version: ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21 (17 by maintainers)

Most upvoted comments

Adding gem 'irb' to your Gemfile also fixes the problem - for some reason on Arch the gem isn’t in the default set of gems, e.g:

% gem list | grep irb
irb (default: 1.3.5)

vs.

# gem list | grep irb
irb (1.3.5)

I suspect this is a packaging thing in Arch but we should probably make sure before closing otherwise we may need to add irb to railties.gemspec if it’s not going to be included in the default gems in future.

The rationale behind splitting irb from ruby distribution is that irb development moved to a separate repository. And ruby distribution is in a weird state right now. From one side they ship irb as a part of default gemset. From other side if a CEV happens then ruby developers suggest to update irb as a standalone gem using rubygems.

default gemset and stanalone gems use different locations. Arch packaging manager does not handle such either/or conditions. So we’ve moved to using irb (and some other components) as standalone gems exclusively.

My suggestion is to add gem irb' to your Gemfile. It is a future-proof solution in case if ruby community decides to de-couple irb completely (which I would vote for).

I was able to reproduce this:

docker run -it archlinux:base-devel bash

in the container:

pacman -Syu ruby
export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
export PATH="$PATH:$GEM_HOME/bin"
gem install rails
rails new irb_test --skip-webpack-install # webpack will fail because no node.js
cd irb_test
bin/rails c

Same Error:

Running via Spring preloader in process 1622
/root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': cannot load such file -- irb (LoadError)
Did you mean?  erb
               drb
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:89:in `register'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:44:in `require'
        from /root/.local/share/gem/ruby/3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/commands/console/console_command.rb:3:in `<main>'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from /root/.local/share/gem/ruby/3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:44:in `block (2 levels) in lookup'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:40:in `each'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:40:in `block in lookup'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:39:in `each'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:39:in `lookup'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/command.rb:76:in `find_by_namespace'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/command.rb:48:in `invoke'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/commands.rb:18:in `<main>'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from /root/.local/share/gem/ruby/3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
        from /irb_test/bin/rails:5:in `<main>'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
        from /root/.local/share/gem/ruby/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
        from /root/.local/share/gem/ruby/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:10:in `block in fork'
        from /root/.local/share/gem/ruby/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:10:in `block in fork'
        from /root/.local/share/gem/ruby/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:8:in `fork'
        from /root/.local/share/gem/ruby/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:8:in `fork'
        from /root/.local/share/gem/ruby/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:26:in `fork'
        from /root/.local/share/gem/ruby/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:8:in `fork'
        from /root/.local/share/gem/ruby/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:26:in `fork'
        from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from -e:1:in `<main>'

I also tried making a plain ruby script that requires irb to make sure irb existed and that worked fine:

# irb_test.rb
require 'irb'
p 'irb required'
ruby irb_test.rb
# => "irb required"

Same error with bootsnap/setup removed:

Running via Spring preloader in process 1698
/root/.local/share/gem/ruby/3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require': cannot load such file -- irb (LoadError)
Did you mean?  erb
               drb
        from /root/.local/share/gem/ruby/3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/commands/console/console_command.rb:3:in `<top (required)>'
        from /root/.local/share/gem/ruby/3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
        from /root/.local/share/gem/ruby/3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:44:in `block (2 levels) in lookup'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:40:in `each'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:40:in `block in lookup'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:39:in `each'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/command/behavior.rb:39:in `lookup'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/command.rb:76:in `find_by_namespace'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/command.rb:48:in `invoke'
        from /root/.local/share/gem/ruby/3.0.0/gems/railties-6.1.3.2/lib/rails/commands.rb:18:in `<top (required)>'
        from /root/.local/share/gem/ruby/3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
        from /root/.local/share/gem/ruby/3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
        from /irb_test/bin/rails:5:in `<top (required)>'
        from /root/.local/share/gem/ruby/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:10:in `block in fork'
        from /root/.local/share/gem/ruby/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:10:in `block in fork'
        from /root/.local/share/gem/ruby/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:8:in `fork'
        from /root/.local/share/gem/ruby/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:8:in `fork'
        from /root/.local/share/gem/ruby/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:26:in `fork'
        from /root/.local/share/gem/ruby/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:8:in `fork'
        from /root/.local/share/gem/ruby/3.0.0/gems/activesupport-6.1.3.2/lib/active_support/fork_tracker.rb:26:in `fork'
        from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from -e:1:in `<main>'

Closing this since it isn’t caused by Rails.

Adding gem 'irb' to your Gemfile also fixes the problem

Can confirm that does indeed solve the problem and irb loads correctly after adding it.

hmm, very confusing. I haven’t found a combination of GEM_HOME and GEM_PATH that finds the irb pacman installs.

Is it safe to say the best advice for this situation is to use a ruby manager like rbenv, rvm or chruby?

(or how ruby is packaged on arch?)

Probably this. Just tried with rvm and worked. The ruby installed by pacman, does not includes ‘irb’…

pacman install:

[root@1921843291cc irb_test]# ls /root/.local/share/gem/ruby/3.0.0/bin
bootsnap  bundle  bundler  byebug  listen  nokogiri  puma  pumactl  racc  rackup  rails  rake  spring  sprockets  thor	tilt

rvm install:

[root@1921843291cc irb_test]# ls /usr/local/rvm/rubies/ruby-3.0.0/bin/
bundle	bundler  erb  executable-hooks-uninstaller  gem  **irb**  racc  rake  rbs  rdoc  ri  ruby  ruby_executable_hooks  typeprof

update: the ruby installed by pacman [https://archlinux.org/packages/extra/x86_64/ruby/], installs a package named ‘ruby-irb’

[root@1921843291cc sbin]# pacman -Ql ruby-irb
...
ruby-irb /usr/bin/irb
...