# Ruby require local file problem

**URL:** <https://www.ruby-forum.com/t/ruby-require-local-file-problem/187814>\
**Category:** Ruby\
**Created:** [April 29, 2010, 7:34pm UTC](https://www.ruby-forum.com/t/ruby-require-local-file-problem/187814 "2010-04-29T19:34:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![svin80](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7bcc69/32.png) [@svin80](https://www.ruby-forum.com/u/svin80)\
**Post date:** [April 29, 2010, 7:34pm UTC](https://www.ruby-forum.com/t/ruby-require-local-file-problem/187814/1 "2010-04-29T19:34:04Z")

</div>

I have two files foo.rb and test.rb in the same folder.

## test.rb

## puts RUBY\_VERSION require ‘foo’

## foo.rb

module Foo  
PATTT = “2323”  
class Foo2  
def f  
puts ‘hello world’  
end  
end  
end

## puts ‘eee’

Running under NetBeans it’s OK. But running test.rb through concole OR  
RubyMine fails with:

C:\USERS\ADMIN\>ruby  
C:\Users\Admin\Documents\NetBeansProjects\RubyApplication1\l  
ib\test.rb  
1.9.1  
C:/Users/Admin/Documents/NetBeansProjects/RubyApplication1/lib/test.rb:2:in  
`req uire': no such file to load -- foo (LoadError) from C:/Users/Admin/Documents/NetBeansProjects/RubyApplication1/lib/test .rb:2:in`’

---

<div class="post-metadata">

**Author:** ![svin80](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7bcc69/32.png) [@svin80](https://www.ruby-forum.com/u/svin80)\
**Post date:** [April 29, 2010, 8:53pm UTC](https://www.ruby-forum.com/t/ruby-require-local-file-problem/187814/2 "2010-04-29T20:53:56Z")

</div>

On Apr 29, 2:34 pm, Svin S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> module Foo
> 
> ```
> from
> 
> ```
> 
> C:/Users/Admin/Documents/NetBeansProjects/RubyApplication1/lib/test  
> rb:2:in `’

Simple: you’re trying to require ‘foo’ from a directory that is not  
the current one.

If both test.rb and foo.rb are located in the same directory, doing  
“ruby path\to\test.rb” will not be able to find foo in the same path.

Now, if you CD into the directory test.rb and foo.rb are located,  
require ‘foo’ will succeed, since the current directory is in the  
$LOAD\_PATH.

That helps?

---

<div class="post-metadata">

**Author:** ![svin80](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7bcc69/32.png) [@svin80](https://www.ruby-forum.com/u/svin80)\
**Post date:** [April 29, 2010, 9:01pm UTC](https://www.ruby-forum.com/t/ruby-require-local-file-problem/187814/3 "2010-04-29T21:01:35Z")

</div>

> Simple: you’re trying to require ‘foo’ from a directory that is not  
> the current one.
> 
> If both test.rb and foo.rb are located in the same directory, doing  
> “ruby path\to\test.rb” will not be able to find foo in the same path.
> 
> Now, if you CD into the directory test.rb and foo.rb are located,  
> require ‘foo’ will succeed, since the current directory is in the  
> $LOAD\_PATH.
> 
> That helps?  
> Thanks, it helps!

Why it’s so different from python/java ☹
