From: Stefano Crocco Date: 2013-01-26T00:44:27+09:00 Subject: Re: Gem loads in irb but not console On Saturday 26 January 2013 Martin Kociman wrote > Hi! > > I have the next problem: I was install a gem. The gem work well in > 'irb', but doesn't work in console. What is the problem? Please, help! > ... > root@iway-cacique:~# irb > irb(main):001:0> require 'rubygems' > => true > irb(main):002:0> require 'selenium-webdriver' > => true > > c. > root@iway-cacique:~# ruby -e 'require "rubygems"' > root@iway-cacique:~# ruby -e 'require "selenium-webdriver"' > -e:1:in `require': no such file to load -- selenium-webdriver > (LoadError) > from -e:1 When you use IRB, you have a single ruby interpreter running, which executes all your commands. So you tell this interpreter first to load rubygems, then to load selenium-webdriver. And all is well. When you use the console, you execute the ruby program twice, which means you get two copies of the interpreter. You first start an interpreter and tell it to load rubygems. It does that, then it closes, not having anything else to do. Then, you launch ruby again and this time tell it to load selenium-webdriver. Now, this second interpreter has nothing in common with the previous one; in particular, it hasn't loaded rubygems. Hence the error. I don't know what exactly you're trying to accomplish, since ruby is usually used with the -e switch only for very short scripts. If you want something longer, you usually use irb, write the script to a file and pass it to ruby, as ruby my_script.rb or type it directly into ruby (which, however, is quite akward): ruby require 'rubygems' require 'selenium-webdriver' ... Note that to have your code executed, you'll have to send a Ctrl+D character. If you really want to use the -e switch, then you should also use the -r switch, which allows to specify libraries to require before executing the script. In your case, you could do the following: ruby -rrubygems -e 'require "selenium-webdriver'" Note that in ruby 1.8, you can't use the -r switch to require gems. For example, this wouldn't have worked: ruby -rrubygems -rselenium-webdriver -e '...' Also, there is a file called ubygems.rb in your rubygems installation which simply requires rubygems and which allows to write ruby -rubygems -e 'require "selenium-webdriver'" instead of -rrubygems. I hope this helps Stefano