Question

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.

Was it helpful?

Solution

You could invoke you ruby script with

ruby -rubygems script.rb

or add rubygems to RUBYOPT

$ export RUBYOPT="rubygems"

OTHER TIPS

put

require 'rubygems'

as first line of your ruby code and be safe. of course you can invoke with -rubygems switch (as Peter Krenn wrote) instead of it

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.

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.

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}"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top