启动Rails服务器时出现JRuby加载错误求助
问题排查:Ruby升级后JRuby加载错误(降级后仍存在)
问题背景
将Ruby版本更新至3.1.3后,持续遇到JRuby加载失败的错误,降级回3.1.2问题依旧。已尝试重装Ruby、更新所有gems,此前无需单独安装JRuby即可正常运行。
错误信息
20:23:24 web.1 | C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require': cannot load such file -- jruby (LoadError) 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/jruby-openssl-0.9.4/lib/jopenssl/load.rb:13:in `<main>' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/jruby-openssl-0.9.4/lib/openssl.rb:1:in `<main>' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/key_generator.rb:4:in `<main>' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/application.rb:6:in `<main>' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails.rb:13:in `<main>' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' 20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' 20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/commands/server/server_command.rb:5:in `<main>' 20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' 20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' 20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command/behavior.rb:44:in `block (2 levels) in lookup' 20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command/behavior.rb:40:in `each' 20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command/behavior.rb:40:in `block in lookup' 20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command/behavior.rb:39:in `each' 20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command/behavior.rb:39:in `lookup' 20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command.rb:73:in `find_by_namespace' 20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command.rb:46:in `invoke' 20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/commands.rb:18:in `<main>' 20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_requ from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/foreman-0.87.2/lib/foreman/vendor/thor/lib/thor/base.rb:444:in `start' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/foreman-0.87.2/bin/foreman:7:in `<top (required)>' from C:/Ruby31-x64/bin/foreman:32:in `load' from C:/Ruby31-x64/bin/foreman:32:in `<main>'
排查与解决步骤
从错误栈可以看出,问题根源是jruby-openssl这个gem——它是专为JRuby设计的,标准Ruby(MRI)完全不需要该gem,现在它被错误加载,导致系统尝试寻找不存在的jruby库。
卸载
jruby-openssl
打开命令行执行:gem uninstall jruby-openssl如果使用Bundler管理依赖,需检查Gemfile和Gemfile.lock,删除
jruby-openssl相关条目,再执行:bundle install清理Bootsnap缓存
Bootsnap会缓存加载路径,残留的旧缓存可能导致问题,执行:bundle exec bootsnap clear或手动删除项目内的
tmp/cache目录。彻底清理gem缓存并重装依赖
执行以下命令:gem cleanup bundle install --clean检查环境配置
查看系统环境变量(如Windows系统/用户变量)、项目初始化脚本(如.env、config/initializers下的文件),确认是否有强制加载jruby相关配置,如有则删除。
内容的提问来源于stack exchange,提问作者xor
相关产品推荐
相关产品推荐

