Rails bin/rails server 启动过程中遇到 LoadError 异常

kakaxi2 · 2016年07月03日 · 最后由 huacnlee 回复于 2016年07月04日 · 3847 次阅读

环境 CentOS7 ruby 2.0.0p598 (2014-11-13) [x86_64-linux] rails (4.2.0) gem( 2.0.14)

在创建好 rail 应用后,执行 bin/rails server 时报告如下的错误,stackoverflow 查看说这个问题在 windows 环境由于 nokogiri 兼容性问题经常出现, 但是没有 linux 环境问题出现这种情况的资料,请谁遇到的话帮忙解答一下。

Warning: You're using Rubygems 2.0.14 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.
/usr/local/share/gems/gems/nokogiri-1.6.8/lib/nokogiri.rb:32:in `require': cannot load such file -- nokogiri/nokogiri (LoadError)
    from /usr/local/share/gems/gems/nokogiri-1.6.8/lib/nokogiri.rb:32:in `rescue in <top (required)>'
    from /usr/local/share/gems/gems/nokogiri-1.6.8/lib/nokogiri.rb:28:in `<top (required)>'
    from /usr/local/share/gems/gems/loofah-2.0.3/lib/loofah.rb:3:in `require'
    from /usr/local/share/gems/gems/loofah-2.0.3/lib/loofah.rb:3:in `<top (required)>'
    from /usr/local/share/gems/gems/rails-html-sanitizer-1.0.3/lib/rails-html-sanitizer.rb:2:in `require'
    from /usr/local/share/gems/gems/rails-html-sanitizer-1.0.3/lib/rails-html-sanitizer.rb:2:in `<top (required)>'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers/sanitize_helper.rb:3:in `require'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers/sanitize_helper.rb:3:in `<top (required)>'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers/text_helper.rb:32:in `<module:TextHelper>'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers/text_helper.rb:29:in `<module:Helpers>'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers/text_helper.rb:6:in `<module:ActionView>'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers/text_helper.rb:4:in `<top (required)>'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers/form_tag_helper.rb:18:in `<module:FormTagHelper>'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers/form_tag_helper.rb:14:in `<module:Helpers>'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers/form_tag_helper.rb:8:in `<module:ActionView>'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers/form_tag_helper.rb:6:in `<top (required)>'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers/form_helper.rb:4:in `require'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers/form_helper.rb:4:in `<top (required)>'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers.rb:50:in `<module:Helpers>'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers.rb:4:in `<module:ActionView>'
    from /usr/local/share/gems/gems/actionview-4.2.0/lib/action_view/helpers.rb:3:in `<top (required)>'
    from /usr/local/share/gems/gems/sprockets-rails-3.1.1/lib/sprockets/rails/context.rb:7:in `<module:Context>'
    from /usr/local/share/gems/gems/sprockets-rails-3.1.1/lib/sprockets/rails/context.rb:6:in `<module:Rails>'
    from /usr/local/share/gems/gems/sprockets-rails-3.1.1/lib/sprockets/rails/context.rb:5:in `<module:Sprockets>'
    from /usr/local/share/gems/gems/sprockets-rails-3.1.1/lib/sprockets/rails/context.rb:4:in `<top (required)>'
    from /usr/local/share/gems/gems/sprockets-rails-3.1.1/lib/sprockets/railtie.rb:7:in `require'
    from /usr/local/share/gems/gems/sprockets-rails-3.1.1/lib/sprockets/railtie.rb:7:in `<top (required)>'
    from /home/sdy/.gem/ruby/gems/sass-rails-5.0.5/lib/sass/rails/railtie.rb:3:in `require'
    from /home/sdy/.gem/ruby/gems/sass-rails-5.0.5/lib/sass/rails/railtie.rb:3:in `<top (required)>'
    from /home/sdy/.gem/ruby/gems/sass-rails-5.0.5/lib/sass/rails.rb:11:in `require'
    from /home/sdy/.gem/ruby/gems/sass-rails-5.0.5/lib/sass/rails.rb:11:in `<top (required)>'
    from /home/sdy/.gem/ruby/gems/sass-rails-5.0.5/lib/sass-rails.rb:1:in `require'
    from /home/sdy/.gem/ruby/gems/sass-rails-5.0.5/lib/sass-rails.rb:1:in `<top (required)>'
    from /usr/local/share/gems/gems/bundler-1.12.5/lib/bundler/runtime.rb:86:in `require'
    from /usr/local/share/gems/gems/bundler-1.12.5/lib/bundler/runtime.rb:86:in `block (2 levels) in require'
    from /usr/local/share/gems/gems/bundler-1.12.5/lib/bundler/runtime.rb:81:in `each'
    from /usr/local/share/gems/gems/bundler-1.12.5/lib/bundler/runtime.rb:81:in `block in require'
    from /usr/local/share/gems/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in `each'
    from /usr/local/share/gems/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in `require'
    from /usr/local/share/gems/gems/bundler-1.12.5/lib/bundler.rb:102:in `require'
    from /home/sdy/railsworkspace/blog/config/application.rb:7:in `<top (required)>'
    from /usr/local/share/gems/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:78:in `require'
    from /usr/local/share/gems/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:78:in `block in server'
    from /usr/local/share/gems/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /usr/local/share/gems/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /usr/local/share/gems/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /usr/local/share/gems/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
    from /home/sdy/railsworkspace/blog/bin/rails:9:in `require'
    from /home/sdy/railsworkspace/blog/bin/rails:9:in `<top (required)>'
    from /home/sdy/.gem/ruby/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in `load'
    from /home/sdy/.gem/ruby/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in `call'
    from /home/sdy/.gem/ruby/gems/spring-1.7.2/lib/spring/client/command.rb:7:in `call'
    from /home/sdy/.gem/ruby/gems/spring-1.7.2/lib/spring/client.rb:30:in `run'
    from /home/sdy/.gem/ruby/gems/spring-1.7.2/bin/spring:49:in `<top (required)>'
    from /home/sdy/.gem/ruby/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `load'
    from /home/sdy/.gem/ruby/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `<top (required)>'
    from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/sdy/railsworkspace/blog/bin/spring:13:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'
  • 条件允许的话,升级 Ruby 至最新版(你的提示信息第一条已经告诉你版本太旧了),使用 RVM 安装,因为 CentOS 和 Debian 的软件包倾向老旧但稳定,这不 Ruby
  • 如果升级到最新 Ruby 并且重新执行 bundle 后还有这个现象,删除 Gemfile.lock,然后重新运行 bundle
  • 稳妥起见,每次执行 bin/rails 之前都先执行 bin/spring stop,除非你的 app 可以正确启动了

重装 Gem,看起来 Nokogiri 的 C 扩展的库有问题

需要 登录 后方可回复, 如果你还没有账号请 注册新账号