Ruby `require': 无法加载此类文件 -- fcgi Dreamhost

Ruby `require': cannot load such file -- fcgi Dreamhost

当尝试 运行 一个 ruby 脚本时 ruby dispatch.fcgi 我收到错误

/pathtorvm/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- fcgi (LoadError)
from /pathtorvm/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from dispatch.fcgi:8:in `<main>'

我正在尝试遵循 Dreamhost 的 Rvm/Rails 安装指南以及多篇博文:

Configuring Rails projects with FastCGI for Dreamhost shared hosting
RAILS 4.0.0 WITH RUBY 2.0 ON A DREAMHOST SHARED SERVER

我正在使用 rvm => 1.26.11,ruby => 2.2.0,rails 4.2.2 成功,甚至尝试过 ruby 2.0.0。我试图将我的所有 env_vars 指向正确的位置,但我不是 100% 确定 $PATH var 设置正确。

我正在使用捆绑器 gem 安装我的 gem 并在 Gemfile 中包含 require 'fcgi'。我还删除了 Gemfile.lock 文件并尝试再次 运行 捆绑安装。我想也许 ruby-2.2.0 导致了问题,但 ruby-2.0.0 产生了相同的结果 & RAILS 4.0.0 WITH RUBY 2.0 ON A DREAMHOST SHARED SERVER 清楚地表明它与 ruby-2.0.0

dispatch.fcgi

#!/pathtorvm/.rvm/rubies/ruby-2.2.0/bin/ruby

# Dreamhost clears environment variables when calling dispatch.fcgi, set again
ENV['RAILS_ENV'] = 'production'
ENV['HOME'] ||= `echo ~`.strip
ENV['GEM_HOME'] = File.expand_path('~/.gems')
ENV['GEM_PATH'] = File.expand_path('~/.gems')
require 'fcgi'
require '/pathtoapplication'sfile/config/boot.rb'
require '/pathtoapplication'sfile/config/environment.rb'

class Rack::PathInfoRewriter
        def initialize(app)
                @app = app
        end

        def call(env)
                env.delete('SCRIPT_NAME')
            parts = env['REQUEST_URI'].split('?')
            env['PATH_INFO'] = parts[0]
            env['QUERY_STRING'] = parts[1].to_s
            @app.call(env)
        end
end

#Rack::Handler::FastCGI.run Rack::PathInfoRewriter.new(ApplicationNamefoundin~../config/application.rb::Application)

原因是因为我用的是rvm。在 dispatch.fcgi

ENV['GEM_HOME'] = File.expand_path('~/.gems')
ENV['GEM_PATH'] = File.expand_path('~/.gems')

应该改为(注意 /gems/ 而不是 /.gems/ - 它将默认为 Dreamhost 的 ruby 而不是我的自定义安装)

ENV['GEM_HOME'] = File.expand_path('~/.rvm/gems/ruby-2.2.0')
ENV['GEM_PATH'] = File.expand_path('~/.rvm/gems/ruby-2.2.0')

感谢Dreamhost的帮助

以上实际上对我一点帮助都没有。我不得不添加这个:

require 'rubygems'
Gem.clear_paths
require 'fcgi'