What is this error?

I seem to have correct include path, but a lot of gems can't be loaded
via "required". What could be the problem?

#!/usr/bin/ruby -w
require "cgi" # cant 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>'

# 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/

First.. paste in your file:
  require 'rubygems'
before another require's:

Hi Alex,

I tried you suggestion. Still getting the same error.

#!/usr/bin/ruby1.9.2
#!/opt/framework3/ruby/bin/ruby -w
#!/usr/bin/ruby -w
require 'rubygems'
require "cgi"
require "action_pack"

./test.rb:6:in `require': no such file to load -- action_pack
(LoadError)
        from ./test.rb:6:in `<main>'

What does
gem list
show?

Colin

Here is the o/p of gem list

# 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).

# gem list -d action_pack
/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 ***

Heh… seems you have problem with RVM load?

As your RVM installed in systemwide maner

check that your $HOME/.bashrc file have this line at the end:
source ‘/usr/local/rvm/scripts/rvm’

If not then add and reload terminal. Then…

  1. Navigate to folder with your script and type that:
    rvm --create --rvmrc 1.9.3@test_sctipt
  2. Then install all needed gems
  3. And replace that:
    #!/usr/bin/ruby1.9.2
    #!/opt/framework3/ruby/bin/​ruby -w
    #!/usr/bin/ruby -w
    with this one:
    #!/usr/bin/env ruby

Hi Alex, thanks a lot for some informative advice.
I tried those things. Still no luck :confused:

# env | grep -i rvm
rvm_bin_path=/usr/local/rvm/bin
GEM_HOME=/usr/local/rvm/gems/ruby-1.9.3-p125
IRBRC=/usr/local/rvm/rubies/ruby-1.9.3-p125/.irbrc
MY_RUBY_HOME=/usr/local/rvm/rubies/ruby-1.9.3-p125
rvm_tar=tar
rvm_path=/usr/local/rvm
rvm_uname=Linux
rvm_prefix=/usr/local
PATH=/usr/local/rvm/gems/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/etc/alternatives/gem-bin
rvm_rvmrc_flag=1
rvm_version=1.10.3
rvm_ruby_string=ruby-1.9.3-p125
GEM_PATH=/usr/local/rvm/gems/ruby-1.9.3-p125:/usr/local/rvm/gems/ruby-1.9.3-p125@global
rvm_delete_flag=0

# env | grep -i ruby
GEM_HOME=/usr/local/rvm/gems/ruby-1.9.3-p125
IRBRC=/usr/local/rvm/rubies/ruby-1.9.3-p125/.irbrc
MY_RUBY_HOME=/usr/local/rvm/rubies/ruby-1.9.3-p125
PATH=/usr/local/rvm/gems/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/etc/alternatives/gem-bin
PWD=/var/www/ruby
rvm_ruby_string=ruby-1.9.3-p125
GEM_PATH=/usr/local/rvm/gems/ruby-1.9.3-p125:/usr/local/rvm/gems/ruby-1.9.3-p125@global
RUBY_VERSION=ruby-1.9.3-p125

Ran rvm --create --rvmrc 1.9.3 to create .rvmrc file in the script's
folder.
Changed to #!/usr/bin/env ruby

head -5 test.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'cgi'
require 'actionpack'

# ./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 ./test.rb:9:in `<main>'

# 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.17
  - 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/

  1. You sure that actionpack is installed?

  2. Instead of
    require ‘actionpack’
    use:

require ‘action_pack’

Yes. actionpack is installed.....

# 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).

# gem list -d action_pack
/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 ***

Hi Alex,
changing it to require 'action_pack' worked.
But other gems has the same issue -

# ./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 -- bundler (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 ./test.rb:8:in `<main>'

# gem list -d bundler
/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 ***

bundler (1.1.2)
    Authors: André Arko, Terence Lee, Carl Lerche, Yehuda Katz
    Rubyforge: http://rubyforge.org/projects/bundler
    Homepage: http://gembundler.com
    Installed at: /usr/local/rvm/gems/ruby-1.9.3-p125

    The best way to manage your application's dependencies

Hmm…

What gives this command?
rvm current

Have you tried require commands from ruby console(irb) ?

Hi Alex,

I was able to solve the issue. Don't know what was wrong, but I removed
ruby, gems, rails, rvm completely from the machine. Rebooted and
installed everything freshly. That worked, now no more errors in loading
any gem.

thanks for your help