# Require command problem

**URL:** <https://rubytalk.org/t/require-command-problem/58856>\
**Category:** ruby-talk\
**Created:** [11 June 2010 11:04 UTC](https://rubytalk.org/t/require-command-problem/58856 "2010-06-11T11:04:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pen\_Ttt](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@Pen\_Ttt](https://rubytalk.org/u/Pen_Ttt)\
**Post date:** [11 June 2010 11:04 UTC](https://rubytalk.org/t/require-command-problem/58856/1 "2010-06-11T11:04:46Z")

</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  
&nbsp;&nbsp;from (irb):2:in `require'  
&nbsp;&nbsp;from (irb):2  
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?

> **···**
>
> from :0  
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Rein\_Henrichs](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rein\_Henrichs](https://rubytalk.org/u/Rein_Henrichs)\
**Post date:** [11 June 2010 11:50 UTC](https://rubytalk.org/t/require-command-problem/58856/2 "2010-06-11T11:50:09Z")

</div>

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.

> **···**
>
> On 2010-06-11 04:04:46 -0700, Pen Ttt said:
> 
> > 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  
> > &nbsp;&nbsp;from (irb):2:in `require'  
> > &nbsp;&nbsp;from (irb):2  
> > &nbsp;&nbsp;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?
> 
> --  
> Rein Henrichs
> 
> > **[Puppet Infrastructure & IT Automation at Scale | Puppet by Perforce](https://www.puppet.com/)**
> >
> > Puppet is the industry-leading automation solution for configuration management, compliance, CI/CD, patch management, IT automation, and more.
> 
> [http://reinh.com](http://reinh.com)

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [11 June 2010 16:18 UTC](https://rubytalk.org/t/require-command-problem/58856/3 "2010-06-11T16:18:37Z")

</div>

Pen Ttt 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:

&nbsp;&nbsp;$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/\<appname\>-\<ver\>/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/...)

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Pen\_Ttt](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@Pen\_Ttt](https://rubytalk.org/u/Pen_Ttt)\
**Post date:** [12 June 2010 02:50 UTC](https://rubytalk.org/t/require-command-problem/58856/4 "2010-06-12T02:50:09Z")

</div>

1.hello.rb  
position: /home/pt/test/hello.rb  
content:  
class Hihi  
def self.hello  
&nbsp;&nbsp;puts "HELLO"  
end  
end  
2.hello.gemspec  
position: /home/pt/test/hello.gemspec  
content:  
Gem::Specification.new do |s|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[s.name](http://s.name) = 'hello'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.version = '0.1.0'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.summary = 'hello gems'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.files = ["/home/pt/test/hello.rb"]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.summary='output hello'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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  
&nbsp;&nbsp;Successfully built RubyGem  
&nbsp;&nbsp;Name: hello  
&nbsp;&nbsp;Version: 0.1.0  
&nbsp;&nbsp;File: hello-0.1.0.gem  
pt@pt-laptop:~$ gem install hello  
WARNING: Installing to ~/.gem since /var/lib/gems/1.8 and  
&nbsp;&nbsp;&nbsp;&nbsp;/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,  
&nbsp;&nbsp;&nbsp;&nbsp;gem executables will not run.  
ERROR: Error installing hello:  
&nbsp;&nbsp;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  
&nbsp;&nbsp;from (irb):1:in `require'  
&nbsp;&nbsp;from (irb):1  
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'?

> **···**
>
> from :0
> 
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Fleck\_Jean-Julien](https://avatars.discourse-cdn.com/v4/letter/f/65b543/32.png) [@Fleck\_Jean-Julien](https://rubytalk.org/u/Fleck_Jean-Julien)\
**Post date:** [12 June 2010 04:23 UTC](https://rubytalk.org/t/require-command-problem/58856/5 "2010-06-12T04:23:00Z")

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

> **···**
>
> --  
> JJ Fleck  
> PCSI1 Lycée Kléber

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [12 June 2010 06:46 UTC](https://rubytalk.org/t/require-command-problem/58856/6 "2010-06-12T06:46:55Z")

</div>

Pen Ttt wrote:

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.files = ["/home/pt/test/hello.rb"]

...

> ERROR: Error installing hello:  
> &nbsp;&nbsp;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.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
