# Require command problem

**URL:** <https://www.ruby-forum.com/t/require-command-problem/190017>\
**Category:** Ruby\
**Created:** [June 11, 2010, 1:04pm UTC](https://www.ruby-forum.com/t/require-command-problem/190017 "2010-06-11T13:04:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [June 11, 2010, 1:04pm UTC](https://www.ruby-forum.com/t/require-command-problem/190017/1 "2010-06-11T13:04:44Z")

</div>

i have write a class ,use command to put in the  
/usr/lib/ruby/1.8/rubygems/Webmovie.rb  
sudo cp /tmp/Webmovie.rb /usr/lib/ruby/1.8/rubygems/Webmovie.rb  
Code.rb is my calss ,also in /usr/lib/ruby/1.8/rubygems/

pt@pt-laptop:~$ irb  
irb(main):001:0\> require ‘Code’  
=\> true  
irb(main):002:0\> require ‘Webmovie’  
LoadError: no such file to load – Webmovie  
from (irb):2:in `require’  
from (irb):2  
from :0  
irb(main):003:0\> require ‘/usr/lib/ruby/1.8/rubygems/Webmovie’  
=\> true  
irb(main):004:0\>

how can i use command require ‘Webmovie’ to get the class work?

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [June 11, 2010, 1:50pm UTC](https://www.ruby-forum.com/t/require-command-problem/190017/2 "2010-06-11T13:50:51Z")

</div>

On 2010-06-11 04:04:46 -0700, Pen T. said:

> LoadError: no such file to load – Webmovie  
> from (irb):2:in `require’  
> from (irb):2  
> from :0  
> irb(main):003:0\> require ‘/usr/lib/ruby/1.8/rubygems/Webmovie’  
> =\> true  
> irb(main):004:0\>
> 
> how can i use command require ‘Webmovie’ to get the class work?

Your filenames should not use uppercase letters. You should not move  
things into the rubygems directory manually. You should access them  
from within your library or from an installed gem. Look at any Ruby  
library to see correct directory structure, file names and use of  
require.

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [June 11, 2010, 6:18pm UTC](https://www.ruby-forum.com/t/require-command-problem/190017/3 "2010-06-11T18:18:35Z")

</div>

Pen T. wrote:

> i have write a class ,use command to put in the  
> /usr/lib/ruby/1.8/rubygems/Webmovie.rb

But /usr/local/lib/1.8/rubygems is not in the load path (i.e. ruby  
doesn’t look for files there), so ruby won’t find it.

$ irb --simple-prompt

> > $LOAD\_PATH  
> > =\> ["/usr/local/lib/site\_ruby/1.8",  
> > “/usr/local/lib/site\_ruby/1.8/x86\_64-linux”, “/usr/local/lib/site\_ruby”,  
> > “/usr/lib/ruby/vendor\_ruby/1.8”,  
> > “/usr/lib/ruby/vendor\_ruby/1.8/x86\_64-linux”,  
> > “/usr/lib/ruby/vendor\_ruby”, “/usr/lib/ruby/1.8”,  
> > “/usr/lib/ruby/1.8/x86\_64-linux”, “.”]

On your system, /usr/local/lib/site\_ruby is probably the appropriate  
place to put ad-hoc libraries. Otherwise, your program can choose the  
location:

$LOAD\_PATH.unshift “/path/to/my/lib”

rubygems itself does add things to $LOAD\_PATH, but they typically are of  
the form /usr/lib/ruby/gems/1.8/gems/-/lib. If you want  
your library to go here, then package it up as a gem, and install the  
gem. (For Ubuntu, with rubygems installed using apt-get, it’ll be  
/var/lib/gems/1.8/…)

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [June 12, 2010, 4:50am UTC](https://www.ruby-forum.com/t/require-command-problem/190017/4 "2010-06-12T04:50:07Z")

</div>

1.hello.rb  
position: /home/pt/test/hello.rb  
content:  
class Hihi  
def self.hello  
puts “HELLO”  
end  
end  
2.hello.gemspec  
position: /home/pt/test/hello.gemspec  
content:  
Gem::Specification.new do |s|  
s.name = ‘hello’  
s.version = ‘0.1.0’  
s.summary = ‘hello gems’  
s.files = ["/home/pt/test/hello.rb"]  
s.summary=‘output hello’  
s.description=‘output hello’  
end  
3.gem build  
pt@pt-laptop:~$gem build /home/pt/test/hello.gemspec  
WARNING: no author specified  
WARNING: no email specified  
WARNING: no homepage specified  
WARNING: no rubyforge\_project specified  
Successfully built RubyGem  
Name: hello  
Version: 0.1.0  
File: hello-0.1.0.gem  
pt@pt-laptop:~$ gem install hello  
WARNING: Installing to ~/.gem since /var/lib/gems/1.8 and  
/var/lib/gems/1.8/bin aren’t both writable.  
WARNING: You don’t have /home/pt/.gem/ruby/1.8/bin in your PATH,  
gem executables will not run.  
ERROR: Error installing hello:  
attempt to install file into “/home/pt/test/hello.rb”  
pt@pt-laptop:~$ irb  
irb(main):001:0\> require ‘hello’  
LoadError: no such file to load – hello  
from (irb):1:in `require’  
from (irb):1  
from :0  
irb(main):002:0\> require ‘/home/pt/test/hello’  
=\> true  
irb(main):003:0\> Hihi.hello  
HELLO  
=\> nil  
irb(main):004:0\>

problem:  
Would you be kind enough to solve this problem for me ?  
1.why in my system  
/var/lib/gems/1.8 and /var/lib/gems/1.8/bin aren’t both writable.  
how to make them writable?  
2.how can i use require command this way: require ‘hello’ not  
require ‘/home/pt/test/hello’?

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [June 12, 2010, 6:23am UTC](https://www.ruby-forum.com/t/require-command-problem/190017/5 "2010-06-12T06:23:42Z")

</div>

Hello,

> Would you be kind enough to solve this problem for me ?  
> 1.why in my system  
> /var/lib/gems/1.8 and /var/lib/gems/1.8/bin aren’t both writable.  
> how to make them writable?

You have to be root to write there:

sudo gem install hello

> 2.how can i use require command this way: require ‘hello’ not  
> require ‘/home/pt/test/hello’?

You have to require rubygems first for your ruby to know where to look  
for gems:

require ‘rubygems’  
require ‘hello’

Cheers,

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [June 12, 2010, 8:46am UTC](https://www.ruby-forum.com/t/require-command-problem/190017/6 "2010-06-12T08:46:53Z")

</div>

Pen T. wrote:

> ```
> s.files = ["/home/pt/test/hello.rb"]
> 
> ```

…

> ERROR: Error installing hello:  
> attempt to install file into “/home/pt/test/hello.rb”

Don’t use absolute path specifications in your gemspec.

I suggest you find a small gem, and copy what they do. That’s what I did  
when I wrote my first gemspec:

> <https://github.com/candlerb/snailgun/blob/master/snailgun.gemspec>

(sorry, I can’t remember which small gem I based this on 🙂

Regards,

Brian.
