Requires rubygems to work in irb but not in script

I have Ubuntu 9.04 Ruby 1.8 Rubygems 1.3.5

In irb,

irb(main):002:0> require 'rubygems' => true 

In script

 $ ./test.rb ./test.rb:2:in `require': no such file to load -- rubygems (LoadError) from ./test.rb:2 $ gem environment RubyGems Environment: - RUBYGEMS VERSION: 1.3.5 - RUBY VERSION: 1.8.6 (2009-08-04 patchlevel 383) [i686-linux] - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8 - RUBY EXECUTABLE: /usr/local/bin/ruby - EXECUTABLE DIRECTORY: /usr/local/bin - RUBYGEMS PLATFORMS: - ruby - x86-linux - GEM PATHS: - /usr/local/lib/ruby/gems/1.8 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - REMOTE SOURCES: - http://gems.rubyforge.org/ $ which ruby /usr/local/bin/ruby 

I think this may have something to do with my PATH, but I'm not sure how or what to fix.

My $ LOAD_PATH variable seems to have a path to gem catalogs.

 $ gem env gemdir /usr/local/lib/ruby/gems/1.8 $ irb irb(main):001:0> $LOAD_PATH => ["/usr/local/lib/ruby/site_ruby/1.8", "/usr/local/lib/ruby/site_ruby/1.8/i686-linux", "/usr/local/lib/ruby/site_ruby", "/usr/local/lib/ruby/1.8", "/usr/local/lib/ruby/1.8/i686-linux", "."] 
+4
source share
2 answers

Check $LOAD_PATH , this variable contains the paths that ruby ​​searches for when you use require .

+1
source

I assume that the shebang line in irb points to a different ruby ​​than the one that is in your PATH. Try

 $ ruby $(type -p irb) 

and see if your "rubygems" works. If not, look at #! line in irb to find out which ruby ​​it uses ...

0
source

Source: https://habr.com/ru/post/1305969/


All Articles