views:

575

answers:

5

Hi people! I haven been all day training to fix this problem but i couldn't.

The question is easy, i don't want to put anymore the require 'rubygems' line everytime i require a gem...

If i put the require 'rubygems' before any other "require" the file runs perfect but if i don't put the require 'rubygems' line the following error occurs:

(...)in `require': no such file to load -- 'gemname' (LoadError)

I suspect that may be there is some path remaining where to check out the gems repository.

I want to ask you if there is a way to do this.

Thanks a lot.

Cheers, Juan.

+2  A: 

You could invoke you ruby script with

ruby -rubygems script.rb

or add rubygems to RUBYOPT

$ export RUBYOPT="rubygems"
Peter Krenn
Hi Peter. I have read the invoke -rubygems solution but in my previous installation i could run any script without that switch/parametre. My previous installation was the same version as the current one with the difference that in the actual i have the problem who originates this topic/question. I try the second solution but i think it doesn't work on windows... Any other solution?
juanmaflyer
Did roddik's answer help?
Peter Krenn
Yes Peter, thanks again.-
juanmaflyer
+1  A: 

In Unix you can:

$ RUBYOPT="rubygems"
$ export RUBYOPT
$ ruby juans_masterpiece.rb

and in Windows:

SET RUBYOPT=rubygems

or right-click on My Computer->Properties->Advanced->Environment Variables and then finally add the RUBYOPT variable there. Next time you open a cmd.exe run set and it will be there.

Jonas Elfström
There's something similar in windows? i'm running ruby 1.8 in win xp sp3. Thanks a lot
juanmaflyer
SET RUBYOPT=rubygems
Jonas Elfström
Thanks a lot that work
juanmaflyer
+1  A: 

You don't have to put it every time you require a gem — you just have to have it before the first time you require a gem. When you require Rubygems, it replaces the default require with a special one that does all the Rubygems magic.

But that's only in 1.8. You don't have to require Rubygems at all in Ruby 1.9 — so that's a very easy solution to the problem as long as you aren't dependent on 1.8-specific things.

Chuck
A: 

Sorry but i couldn't fix this problem yet.

The:

$ RUBYOPT="rubygems"
$ export RUBYOPT

seems not to work on my pc (win xp)

juanmaflyer
A: 

Right-click the Computer Icon, then select Properties, then Additional system parameters, then Environment variables, there is a GUI for changing opts, click Create, put name and value, OK. This is an approximate translation of how you do this on windows 7, if you can't find the place try to google for "changing environment variables in {your windows version here}"

roddik
Thanks a lot! That worked!
juanmaflyer
Oh, but when i restart windows that VARIABLE isn't anymore... Some way to make that variable reboot-proof?
juanmaflyer
did you add your variable to user variables (upper list) or to system variables?
roddik