Ruby - 无法加载带有“必需”的gems,无法运行rails

时间:2012-03-22 05:15:34

标签: ruby-on-rails ruby

我似乎有正确的包含路径,但无法加载很多宝石 通过“必需”。可能是什么问题?


test.rb

#!/usr/bin/ruby -w
require "cgi" # can load this
require "actionpack" # can not load this

/var/www/ruby/test.rb

/var/www/ruby/test.rb:3:in `require': no such file to load --
/var/lib/gems/1.9.2/gems/passenger-3.0.11/test/stub/vendor_rails/minimal/actionpack
(LoadError)
        from /var/www/ruby/test.rb:3:in `<main>'

rails服务器

/root/src/config/boot.rb:6:in `require': no such file to load --
bundler/setup (LoadError)
        from /root/src/config/boot.rb:6:in `<top (required)>'
        from script/rails:5:in `require'
        from script/rails:5:in `<main>'

gem env

RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.7
  - RUBY VERSION: 1.9.2 (2010-07-02 patchlevel -1) [i486-linux]
  - INSTALLATION DIRECTORY: /var/lib/gems/1.9.2/gems/
  - RUBY EXECUTABLE: /usr/bin/ruby1.9.2
  - EXECUTABLE DIRECTORY: /var/lib/gems/1.9.2/gems/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /var/lib/gems/1.9.2/gems/
     - /root/.gem/ruby/1.9.2
     - /var/lib/gems/1.9.2
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

ls -l /var/lib/gems/1.9.2/gems /

total 296
drwxr-xr-x  4 root root 4096 2011-05-10 12:05 abstract-1.0.0
drwxr-xr-x  3 root root 4096 2011-05-10 12:05 actionmailer-3.0.6
drwxr-xr-x  3 root root 4096 2012-03-15 17:50 actionmailer-3.2.2
drwxr-xr-x  3 root root 4096 2012-03-21 18:59 actionpack-3.2.2
drwxr-xr-x  3 root root 4096 2011-05-10 12:05 activemodel-3.0.6
drwxr-xr-x  3 root root 4096 2012-03-15 17:50 activemodel-3.2.2
drwxr-xr-x  4 root root 4096 2011-05-10 12:05 activerecord-3.0.6
drwxr-xr-x  4 root root 4096 2012-03-15 17:50 activerecord-3.2.2
drwxr-xr-x  4 root root 4096 2011-05-10 12:05 activeresource-3.0.6
drwxr-xr-x  4 root root 4096 2012-03-15 17:50 activeresource-3.2.2
drwxr-xr-x  3 root root 4096 2011-05-10 12:05 activesupport-3.0.6
drwxr-xr-x  3 root root 4096 2012-03-15 17:50 activesupport-3.2.2
drwxr-xr-x  4 root root 4096 2012-03-14 15:21 akami-1.0.0
drwxr-xr-x  4 root root 4096 2011-05-10 12:05 arel-2.0.9
drwxr-xr-x  4 root root 4096 2012-03-15 17:50 arel-3.0.2
drwxr-xr-x  6 root root 4096 2011-05-10 12:05 builder-2.1.2
drwxr-xr-x  5 root root 4096 2012-03-15 17:50 builder-3.0.0
drwxr-xr-x  2 root root 4096 2012-03-21 18:17 bundle-0.0.1
drwxr-xr-x  6 root root 4096 2012-03-21 18:39 bundler-1.1.2
drwxr-xr-x  4 root root 4096 2012-03-15 17:56 daemon_controller-1.0.0
drwxr-xr-x  5 root root 4096 2011-05-10 12:05 diff-lcs-1.1.2
drwxr-xr-x 10 root root 4096 2011-05-10 12:05 erubis-2.6.6
drwxr-xr-x 10 root root 4096 2012-03-15 17:50 erubis-2.7.0
drwxr-xr-x  5 root root 4096 2011-05-10 12:05 factory_girl-1.3.3
drwxr-xr-x  5 root root 4096 2012-03-15 17:56 fastthread-1.0.7
drwxr-xr-x  4 root root 4096 2012-03-14 15:21 gyoku-0.4.4
drwxr-xr-x  3 root root 4096 2012-03-15 17:50 hike-1.2.1
drwxr-xr-x  4 root root 4096 2012-03-14 15:21 httpi-0.9.6
drwxr-xr-x  5 root root 4096 2011-05-10 12:05 i18n-0.5.0
drwxr-xr-x  5 root root 4096 2012-03-15 17:50 i18n-0.6.0
drwxr-xr-x  4 root root 4096 2012-03-15 17:50 journey-1.0.3
drwxr-xr-x 10 root root 4096 2012-03-15 17:50 json-1.6.5
drwxr-xr-x  3 root root 4096 2012-03-14 15:35 libv8-3.3.10.4-x86-linux
drwxr-xr-x  3 root root 4096 2011-05-10 12:05 mail-2.2.19
drwxr-xr-x  3 root root 4096 2012-03-15 17:50 mail-2.4.4
drwxr-xr-x  4 root root 4096 2011-05-10 12:05 mime-types-1.16
drwxr-xr-x  4 root root 4096 2012-03-15 17:50 multi_json-1.1.0
drwxr-xr-x  7 root root 4096 2012-03-15 21:37 mysql-2.8.1
drwxr-xr-x  7 root root 4096 2011-05-10 12:05 nokogiri-1.4.4
drwxr-xr-x  5 root root 4096 2012-03-14 15:21 nori-1.1.0
drwxr-xr-x 14 root root 4096 2012-03-21 18:33 passenger-3.0.11
drwxr-xr-x  4 root root 4096 2011-05-10 12:05 polyglot-0.3.1
drwxr-xr-x  7 root root 4096 2011-05-08 23:16 rack-1.2.2
drwxr-xr-x  7 root root 4096 2012-03-16 20:59 rack-1.4.1
drwxr-xr-x  6 root root 4096 2012-03-15 17:50 rack-cache-1.2
drwxr-xr-x  3 root root 4096 2011-05-10 12:05 rack-mount-0.6.14
drwxr-xr-x  3 root root 4096 2012-03-15 17:50 rack-ssl-1.3.2
drwxr-xr-x  4 root root 4096 2011-05-10 12:05 rack-test-0.5.7
drwxr-xr-x  4 root root 4096 2012-03-15 17:50 rack-test-0.6.1
drwxr-xr-x  6 root root 4096 2012-03-15 21:37 radius-0.7.3
drwxr-xr-x  3 root root 4096 2011-05-10 12:05 rails-3.0.6
drwxr-xr-x  2 root root 4096 2012-03-15 17:50 rails-3.2.2
drwxr-xr-x  4 root root 4096 2011-05-10 12:05 railties-3.0.6
drwxr-xr-x  5 root root 4096 2012-03-15 17:50 railties-3.2.2
drwxr-xr-x  6 root root 4096 2011-05-10 12:05 rake-0.8.7
drwxr-xr-x  5 root root 4096 2012-03-15 17:50 rdoc-3.12
drwxr-xr-x  8 root root 4096 2011-05-10 12:05 RedCloth-4.2.5
drwxr-xr-x  3 root root 4096 2011-05-10 12:06 rspec-2.5.0
drwxr-xr-x  7 root root 4096 2011-05-10 12:05 rspec-core-2.5.2
drwxr-xr-x  5 root root 4096 2011-05-10 12:05 rspec-expectations-2.5.0
drwxr-xr-x  6 root root 4096 2011-05-10 12:05 rspec-mocks-2.5.0
drwxr-xr-x  6 root root 4096 2011-05-10 12:06 rspec-rails-2.5.0
drwxr-xr-x  4 root root 4096 2012-03-21 18:32 rvm-1.9.2
drwxr-xr-x  4 root root 4096 2012-03-14 15:37 savon-0.9.9
drwxr-xr-x  3 root root 4096 2012-03-15 17:50 sprockets-2.1.2
drwxr-xr-x  7 root root 4096 2011-05-10 12:06 sqlite3-ruby-1.2.5
drwxr-xr-x  8 root root 4096 2012-03-14 15:35 therubyracer-0.9.10
drwxr-xr-x  5 root root 4096 2011-05-10 12:05 thor-0.14.6
drwxr-xr-x  5 root root 4096 2012-03-15 17:50 tilt-1.3.3
drwxr-xr-x  7 root root 4096 2011-05-10 12:05 treetop-1.4.9
drwxr-xr-x  4 root root 4096 2011-05-10 12:05 tzinfo-0.3.27
drwxr-xr-x  4 root root 4096 2012-03-15 17:50 tzinfo-0.3.32
drwxr-xr-x  4 root root 4096 2012-03-14 15:21 wasabi-2.1.0
drwxr-xr-x  5 root root 4096 2012-03-16 19:11 webrick-1.3.1

我在新路径中重新安装了ruby(因此路径与我之前的帖子不同)。但仍有同样的问题。

# ruby -v
ruby 1.9.3p125 (2012-02-16 revision 34643) [i686-linux]
# gem -v
/usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/yaml.rb:56:in `<top 
(required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your 
ruby.
1.8.19

# gem env
/usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/yaml.rb:56:in `<top 
(required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your 
ruby.
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.19
  - RUBY VERSION: 1.9.3 (2012-02-16 patchlevel 125) [i686-linux]
  - INSTALLATION DIRECTORY: /usr/local/rvm/gems/ruby-1.9.3-p125
  - RUBY EXECUTABLE: /usr/local/rvm/rubies/ruby-1.9.3-p125/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/rvm/gems/ruby-1.9.3-p125/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /usr/local/rvm/gems/ruby-1.9.3-p125
     - /usr/local/rvm/gems/ruby-1.9.3-p125@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/



# gem list -d actionpack
/usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/yaml.rb:56:in `<top
(required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your
ruby.

*** LOCAL GEMS ***

actionpack (3.2.2)
    Author: David Heinemeier Hansson
    Homepage: http://www.rubyonrails.org
    Installed at: /usr/local/rvm/gems/ruby-1.9.3-p125

    Web-flow and rendering framework putting the VC in MVC (part of
    Rails).

TEST.RB - 
#!/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/ruby -w
###!/usr/bin/ruby -w # copy of above binary
require 'rubygems'
require 'cgi'
require 'actionpack'

# /var/www/ruby/test.rb
/usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- actionpack (LoadError)
        from 
/usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /var/www/ruby/test.rb:8:in `<main>'

我尝试添加require“rubygems”。这也没用。仍然得到同样的错误。 嗨Bhushan nad Tass.Yes我正在使用rvm。我试过捆绑安装。 #bundler install bundler:command not found

1 个答案:

答案 0 :(得分:5)

这应该有效:

#!/usr/bin/ruby -w
require "rubygems"
require "cgi" # can load this
require "actionpack" # can not load this

CGI是一个标准库,而不是宝石,这就是你可以加载它的原因。为了加载宝石,首先require "rubygems"

<强>更新

此外,请尝试require "action_pack"而不是“actionpack”。自Rails 3以来,其他活跃的* Rails宝石也发生了变化。它们仍称为相同,activesupport例如,但必须在中间加下划线:active_support

正如此处提到的其他人一样,请尝试更新 gem 计划,您的版本已经很老了:gem update --system