Ruby Strange Error

2019-03-04 04:07发布

Whenever I require a file in ruby or irb I get this error:

LoadError: no such file to load -- (insert any filename).rb
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from (irb):1
    from /usr/bin/irb1.9.1:12:in `<main>'

It happens even if the file exists I am using ruby1.9.1 and to my knowledge, I have not installed rubygems. I am running on Ubuntu 10.10 Maverick Meerkat. Please help, this problem is very annoying! Thanks in advance, ell.

EDIT: I forgot to say that no matter where the file is, even if its in the same directory and definately exists I always get this error.

3条回答
趁早两清
2楼-- · 2019-03-04 04:32

Rubygems is installed with ruby 1.9 by default.

Check that the file you are trying to load is in a directory listed in the variable $: or specify the entire path to the file in the require. Or, add the directory to $: explicitly:

$: << '/my/lib/path'
require 'mylib'
查看更多
Root(大扎)
3楼-- · 2019-03-04 04:39

In Ruby 1.9.2, which I guess is the version you are using, the current directory is no longer in the $LOAD_PATH. If you want to require files relative to the path of the file that the require call is in, you should use require_relative instead.

If you really want to require files relative to the current directory, then you can add the current directory to the $LOAD_PATH like so:

$LOAD_PATH << '.'

However, this change was made for a reason, so you shouldn't do that lightly. After all, this will make your app behave more or less randomly, depending on what directory you just happened to be in, when you started the app. Worse, an attacker can get you to execute arbitrary code on his behalf if he can get you to run the app from a directory under his control.

查看更多
贼婆χ
4楼-- · 2019-03-04 04:42

Are you using p0? I got that a lot on ruby-1.9.2-p0. Try doing an unlinked (e.g., no using --with-baseruby) ./configure set, in other words

curl ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p136.tar.gz | tar xz
cd ruby-1.9.2-p136
./configure
make -j2
sudo make install

from the beginning. For me, that fixed syck not being there (though a different problem sprug up :/), yaml, even stringio and zlib!

查看更多
登录 后发表回答