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

I have not trained all day to fix this problem, but I could not.

The question is simple, I don’t want to put the string “rubygems” every time I need a gem ...

If I put the requirement "rubygems" before any other "requires", the file will work perfectly, but if I do not put the line "rubygems", the following error occurs:

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

I suspect there might be some way left where you can check out the gem repository.

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

Thank you very much.

Cheers, Juan.

+4
source share
5 answers

You can call ruby ​​script with

ruby -rubygems script.rb 

or add rubygems to RUBYOPT

 $ export RUBYOPT="rubygems" 
+18
source

to set

 require 'rubygems' 

like the first line of your ruby ​​code and be safe. of course, you can call with the -rubygems key (as Peter Krenn wrote) instead

+5
source

On Unix, you can:

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

and on Windows:

 SET RUBYOPT=rubygems 

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

+3
source

You do not need to put it every time you need a gem - you just have to have it before you need a gem for the first time. When you require Rubygems, it replaces the default special one, which does all the magic of Rubygems.

But this is only in 1.8. You do not need to require Rubygems at all in Ruby 1.9 - so this is a very simple solution to the problem if you are not dependent on things specific to 1.8.

+2
source

Right-click the Computer icon, then select Properties, then Advanced System Settings, Environment Variables, a GUI appears to change the selection, click Create, enter a name and value, OK. This is a rough translation of how you do it in Windows 7, if you cannot find this place, try google to "change the environment variables in {your version of Windows here]"

0
source

All Articles