无法加载此类文件 -- 捆绑器/设置 (LoadError)

人气:464 发布:2022-10-16 标签: ruby-on-rails-4 rubygems passenger ruby-2.0

问题描述

我正在使用 Ruby 2.0 设置 Rails 4 应用程序,但我得到无法启动 Web 应用程序"并得到以下跟踪:

I'm setting Rails 4 application with Ruby 2.0, but I'm getting "Web application could not be started" and get this trace:

cannot load such file -- bundler/setup (LoadError)
  /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53:in `require'
  /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53:in `require'
  /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19/lib/phusion_passenger/loader_shared_helpers.rb:212:in `run_load_path_setup_code'
  /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19/helper-scripts/rack-preloader.rb:96:in `preload_app'
  /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19/helper-scripts/rack-preloader.rb:150:in `<module:App>'
  /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19/helper-scripts/rack-preloader.rb:28:in `<main>'

我的 apache2.conf 是:

My apache2.conf is:

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19/buildout/apache2/mod_passenger.so
   PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19
   PassengerDefaultRuby /usr/local/bin/ruby

bundle -v 是:

Bundler version 1.3.5

ruby -v 是:

ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

gem env 是:

RubyGems Environment:
  - RUBYGEMS VERSION: 2.1.5
  - RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /usr/local/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/lib/ruby/gems/1.8/bin
  - SPEC CACHE DIRECTORY: /root/.gem/specs
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /root/.gems/bin
     - /usr/lib/ruby/gems/1.8/bin/
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/bin/X11
     - /usr/games
     - /usr/sbin
     - /sbin

echo $GEM_PATH 是:

/usr/lib/ruby/gems/1.8:/usr/lib/ruby/gems/1.8

GEM_PATH 不应该是 /usr/lib/ruby/gems/2.0 吗?

我在apache2.conf的虚拟主机里面添加了:

Inside the virtual host in apache2.conf I added:

SetEnv GEM_HOME /usr/lib/ruby/gems/1.8

现在它正在工作.

这是解决这个问题的正确方法吗?

Is it the right way to fix this?

推荐答案

可能是在您安装 2.0 之前,您的系统上安装了以前的 Ruby 环境?这可能有一个现有的 GEM_PATH 指向/1.8 目录,2.0 版的安装只是保留了该目录.

It could be that there was a previous Ruby env installed on your system prior to your installation of 2.0? This might have had an existing GEM_PATH that lead to the /1.8 directory which the installation of version 2.0 simply kept.

那么,您可能遇到的问题是,Passenger/Apache 在/2.0 目录中查找,而实际上 gem 位于/1.8 目录中.因此,您明确告诉 apache 使用/1.8 目录对于解决问题是有意义的.

The problem you where likely having, then, was that Passenger/Apache was looking in the /2.0 directory when in fact the gems were in the /1.8 directory. Your explicitly telling apache to use the /1.8 directory thus makes sense to fix the problem.

SetEnv GEM_HOME /usr/lib/ruby/gems/1.8

您也可以尝试使用 Ruby 版本管理器 来处理多个 Ruby 环境.

You might also try using the Ruby Version Manager to handle multiple Ruby envs.

我在 Google 上找到的一些东西:

Some things I found in Google:

刚接触 Ruby 并且遇到了 LOAD_PATH 问题http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices/http://guides.rubygems.org/faqs/

776