You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ruby 2.7.8+Rails 6执行bin/rails c报LoadError问题求助

Rails 6 + Ruby 2.7.8控制台启动LoadError报错分析

报错核心信息

执行bin/rails c时触发如下错误:

Traceback (most recent call last):
    18: from bin/rails:9:in `<main>'
    17: from /usr/local/bundle/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    16: from /usr/local/bundle/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    15: from /usr/local/bundle/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    14: from /usr/local/bundle/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    13: from /usr/local/bundle/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    12: from /usr/local/bundle/gems/railties-6.1.7.3/lib/rails/commands.rb:18:in `<main>'
    11: from /usr/local/bundle/gems/railties-6.1.7.3/lib/rails/command.rb:48:in `invoke'
    10: from /usr/local/bundle/gems/railties-6.1.7.3/lib/rails/command/base.rb:69:in `perform'
     9: from /usr/local/bundle/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
     8: from /usr/local/bundle/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
     7: from /usr/local/bundle/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
     6: from /usr/local/bundle/gems/railties-6.1.7.3/lib/rails/commands/console/console_command.rb:102:in `perform'
     5: from /usr/local/bundle/gems/railties-6.1.7.3/lib/rails/commands/console/console_command.rb:19:in `start'
     4: from /usr/local/bundle/gems/railties-6.1.7.3/lib/rails/commands/console/console_command.rb:70:in `start'
     3: from /usr/local/lib/ruby/2.7.0/irb.rb:393:in `start'
     2: from /usr/local/lib/ruby/2.7.0/irb/init.rb:18:in `setup'
     1: from /usr/local/lib/ruby/2.7.0/irb/init.rb:121:in `init_error'
/usr/local/lib/ruby/2.7.0/irb/locale.rb:121:in `load': No such file to load -- irb/error.rb (LoadError)

报错原因

  1. IRB标准库文件缺失/损坏:irb/error.rb是Ruby 2.7标准库的核心文件,若系统Ruby安装不完整或文件被意外删除,会触发此错误。
  2. Bootsnap缓存异常:Bootsnap(版本1.7.3)的加载路径缓存可能存在脏数据,导致无法正确定位IRB相关文件。
  3. 版本兼容性冲突:老旧的Bootsnap版本(1.7.3)与Ruby 2.7.8存在兼容问题,干扰了IRB的初始化流程。

解决步骤

  • 清除Bootsnap缓存:
    执行命令清除缓存后重试:
    bundle exec bootsnap clear
    bin/rails c
    
  • 临时禁用Bootsnap启动控制台:
    验证是否为缓存问题:
    DISABLE_BOOTSNAP=1 bin/rails c
    
    若能正常启动,建议升级Bootsnap到兼容版本(如1.16.x),修改Gemfile后重新安装:
    gem 'bootsnap', '~> 1.16'
    
    bundle install
    
  • 修复Ruby安装:
    若上述方法无效,说明Ruby标准库损坏,可通过版本管理工具(rbenv/rvm)重新安装Ruby 2.7.8:
    # rbenv示例
    rbenv uninstall 2.7.8
    rbenv install 2.7.8
    bundle install
    
  • 重新安装依赖:
    执行命令确保所有gem依赖完整:
    bundle install
    

内容的提问来源于stack exchange,提问作者Sig

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 11:12:10