Ruby 1.9.1 Load Path Craziness - ruby

Ok, I've just spent the 4 hours trying to figure this one out without success. I've tried all the usual suspects and googled every combination of ruby 1.9.1, load path, gems, mac os x,freebsd,prawn and other stuff. The bottom line is this:
When I compile ruby1.9.1-p129 from sources on mac os x 10.5, the default load path ($:) I get is:
ruby -e "puts $:"
/usr/local/lib/ruby/gems
/usr/local/lib/ruby/site_ruby/1.9.1
/usr/local/lib/ruby/site_ruby/1.9.1/i386-darwin9.7.0
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/vendor_ruby/1.9.1
/usr/local/lib/ruby/vendor_ruby/1.9.1/i386-darwin9.7.0
/usr/local/lib/ruby/vendor_ruby
/usr/local/lib/ruby/1.9.1
/usr/local/lib/ruby/1.9.1/i386-darwin9.7.0
.
when I install the prawn gem, for example, I get:
gem which prawn
(checking gem prawn-0.5.0.1 for prawn)
/prawn.rb
and when I try to require it I get:
ruby -e "require 'prawn'"
-e:1:in `require': no such file to load -- prawn (LoadError)
from -e:1:in `'
The only way I've been able to resolve this is by doing something stupid like this:
$: << "/usr/local/lib/ruby/gems/1.9.1/gems/prawn-0.5.0.1/lib"
which, of course, is utterly ridiculous. So the question is how do I get ruby 1.9.1 to recognize and follow the correct gems path? I've never had this issue with 1.8.7 so I'm assuming it 1.9.1 specific. I feel I'm missing something completely obvious here and any help would be much appreciated!

setting GEM_PATH=/usr/local/lib/ruby/gems/1.9.1
solved the problem. I knew it was something simple. Just aggravates me that it took ALL DAY to figure out!! This is due to never having this issue with 1.8.7 and of course NOT RTFM!!

same problem on kubuntu karmic.
installation:
$ sudo apt-get install build-essential ruby1.9.1-full libsqlite3 libsqlite3-dev rubygems1.9
$ sudo gem install sqlite3-ruby rails thin --no-rdoc --no-ri
result:
$ ruby -e "require 'rubygems'; require 'sqlite3'"
-e:1:in `require': no such file to load -- sqlite3 (LoadError)
from -e:1:in `<main>'
solution:
$ export GEM_PATH=/usr/lib/ruby1.9.1/gems/1.9.1/

Next time you have such an issue, don't forget to run gem env from the command line. This is what happens on Windows, but the principle is much the same:
C:\Documents and Settings\a.grimm>gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.5
- RUBY VERSION: 1.9.1 (2010-01-10 patchlevel 378) [i386-mingw32]
- INSTALLATION DIRECTORY: C:/Ruby19/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: C:/Ruby19/bin/ruby.exe
- EXECUTABLE DIRECTORY: C:/Ruby19/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- C:/Ruby19/lib/ruby/gems/1.9.1
- C:/Documents and Settings/a.grimm/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://gems.rubyforge.org/

require 'rubygems'
require 'prawn'
Unless things have changed in 1.9 that you no longer need to require rubygems first.

I'm looking for a different answer to the same problem. In some situations (ie. system start up tasks) setting environment variables before ruby runs is impossible.
Is there some way in running ruby (v >= 1.9.1) code to require gems? Without setting GEM_PATH?

Related

ruby - require & cannot load such file

I'm new to ruby and I have a problem loading gems.
I've read every topic about this on SO but I couldn't figure out how to make it work :/
I'm on a fresh install of Ruby 1.9.3 and RubyGems 1.8.11
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.11
- RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [i386-mingw32]
- INSTALLATION DIRECTORY: D:/dev/Ruby/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: D:/dev/Ruby/bin/ruby.exe
- EXECUTABLE DIRECTORY: D:/dev/Ruby/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- D:/dev/Ruby/lib/ruby/gems/1.9.1
- D:/aoi/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
I've installed the gem twice, once from command line
gem install soap4r
And second time i've tried to use RubyMine installer, but the result where the same,
when I try to
require 'rubygems'
resuire 'soap'
The output is the same :
LoadError: cannot load such file -- soap
from D:/dev/Ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from D:/dev/Ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):1
from D:/dev/Ruby/bin/irb:12:in `<main>'
Thank you for your help.
Get this https://github.com/spox/soap4r-spox and patch your ruby with it, its the default soap module for ruby but was pulled out of 1.9 versions
Try to add this to the top of your file:
gem 'soap4r'
require 'soap/wsdlDriver'
Or as an alternative try Savon
Have you checked that you do not run multiple different ruby versions ? Then your gems are not bound to the correct ruby version.
Moreover, I notice something strange :
http://rubygems.org/gems/soap : "This gem has been yanked, but it is still available for download for other gems that may have depended on it"
On the contrary, there seems to be another more interesting gem around : soap4r.
There is a tuto here. I especially noticed that sort of lines :
require "soap/rpc/standaloneserver"
That means "require soap" may not be sufficient in your case.

Error installing any gems on IronRuby

I am brand new to Ruby as of today. I installed IronRuby as I am a .NET developer and it seems to have a lighter footprint for Windows 7.
Things have been proceeding well, until I needed to install a Gem to parse HTML. I am issuing the following command:
igem install rokogiri
and receiving the following error:
ERROR: While executing gem ... (NoMethodError)
undefined method `set_params' for #<OpenSSL::SSL::SSLContext:0x00001ba>
Running igem env yields:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [i386-mswin32]
- INSTALLATION DIRECTORY: C:/Program Files (x86)/IronRuby 1.1/Lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: "C:/Program Files (x86)/IronRuby 1.1/bin/ir.exe"
- EXECUTABLE DIRECTORY: C:/Program Files (x86)/IronRuby 1.1/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-dotnet-4.0
- GEM PATHS:
- C:/Program Files (x86)/IronRuby 1.1/Lib/ruby/gems/1.9.1
- P:/.gem/ironruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
My searches on Google have been fruitless. Does anyone have any suggestions?
Thanks!
The error happens in using OpenSSL library.
So this problem can be solved to use ruby standard OpenSSL library, not the library of IronRuby.
I think you can install the library in the following procedure.
Invalidate the function of SSL verifying once.
Add the next line to ~/.gemrc(%HOME%\.gemrc) file.
(if it doesn't exit, create)
:ssl_verify_mode: 0
In this, 'igem' is usabled.
But this state isn't recommend.
Install OpenSSL library, like this :
> igem install rubysl-openssl
And, restore ~/.gemrc file.
'igem' remains to be usabled.
For anyone else that comes across this a solution that worked for me was to use the standard Ruby gem command and set the install directory to the IronRuby gem location.
gem install --install-dir "c:/Program Files (x86)/IronRuby 1.1/lib/ironruby/gems/1.8" -V json_pure
igem does look like it's a very basic Ruby script that wraps up the Ruby gem command. The OpenSSL error seems to be a bit of a red herring and is probably because the default gem repository URL now redirects to a different location and the igem script doesn't deal with that.

Ruby gem environment issue - LoadError: no such file to load -- robots

I'm attempting to write a crawler using the anemone gem, which requires the robots gem. For whatever reason, robots absolutely will not include. Here is some of my environment info:
$ gem list -d robots
*** LOCAL GEMS ***
robots (0.10.1)
Author: Kyle Maxwell
Homepage: http://github.com/fizx/robots
Installed at: /usr/local/lib/ruby/gems/1.9.1
Simple robots.txt parser
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.10
- RUBY VERSION: 1.9.2 (2011-02-18 patchlevel 180) [x86_64-darwin10.7.0]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-10
- GEM PATHS:
- /usr/local/lib/ruby/gems/1.9.1
- /Users/ryan/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
$ gem which robots
/usr/local/lib/ruby/gems/1.9.1/gems/robots-0.10.1/lib/robots.rb
Any ideas? All other gems load correctly, I've never had this problem before. Note that I am using ruby version 1.9, so rubygems is implicitly required. Adding
require 'rubygems'
...to the front of a script returns false, since the file is already included, and does not help the situation. Any ideas?
EDIT: Posting examples of failing code. Please note that rubygems returning false does not mean rubygems cannot load - rather that it has already been loaded. See this post: http://www.ruby-forum.com/topic/157442
$ irb
irb(main):001:0> require 'rubygems'
=> false
irb(main):002:0> require 'active_record'
=> true
irb(main):003:0> require 'mechanize'
=> true
irb(main):004:0> require 'robots'
LoadError: no such file to load -- robots
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from (irb):4
from /usr/local/bin/irb:12:in `<main>'
irb(main):005:0>
It looks like the gem has been created with the wrong permissions; there's a bug opened for this on github.
Changing the permissions with
sudo chmod a+r /usr/local/lib/ruby/gems/1.9.1/gems/robots-0.10.1/lib/robots.rb
should fix it, but watch out for other permission issues. You might be better with
sudo chmod -R a+r /usr/local/lib/ruby/gems/1.9.1/gems/robots-0.10.1
to recursively make all the files in the gem readable.
The robots.rb file (and some others) is being installed with the permissions -rw-rw----, so anyone using a local install of rvm or similar where gems are installed as the local user won't have been affected by this.

Gem found in irb, not in Ruby

I have some gems installed, and I'm trying to use them in a Ruby app:
require 'rubygems'
require 'mygem'
When I run the app, though, I get this error: <internal:lib/rubygems/custom_require>:29:inrequire': no such file to load -- mygem (LoadError)`
But if I try requiring the gem inside irb (making sure to `require 'rubygems' first), it works fine. What am I supposed to do? I tried googling for this problem, but didn't understand.
Running a which on ruby, gem, and irb shows that they're all in /opt/local/bin/, i.e.,
> which ruby
/opt/local/bin/ruby
> which gem
/opt/local/bin/gem
> which irb
/opt/local/bin/irb
Update to answer the questions posed (yep, irb and ruby are pointing to different folders):
$LOAD_PATH and $: in irb both contain seem to be pointing to ruby 1.8 folders:
/opt/local/lib/ruby/site_ruby/1.8
/opt/local/lib/ruby/site_ruby/1.8/i686-darwin10
/opt/local/lib/ruby/site_ruby
/opt/local/lib/ruby/vendor_ruby/1.8
/opt/local/lib/ruby/vendor_ruby/1.8/i686-darwin10
/opt/local/lib/ruby/vendor_ruby
/opt/local/lib/ruby/1.8
/opt/local/lib/ruby/1.8/i686-darwin10
.
$: in ruby points to ruby 1.9.1 folders:
/usr/local/lib/ruby/site_ruby/1.9.1
/usr/local/lib/ruby/site_ruby/1.9.1/i386-darwin9.8.0
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/vendor_ruby/1.9.1
/usr/local/lib/ruby/vendor_ruby/1.9.1/i386-darwin9.8.0
/usr/local/lib/ruby/vendor_ruby
/usr/local/lib/ruby/1.9.1
/usr/local/lib/ruby/1.9.1/i386-darwin9.8.0
gem env shows
RubyGems Environment:
- RUBYGEMS VERSION: 1.4.1
- RUBY VERSION: 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10]
- INSTALLATION DIRECTORY: /opt/local/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /opt/local/bin/ruby
- EXECUTABLE DIRECTORY: /opt/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-10
- GEM PATHS:
- /opt/local/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "gempath" => ["/opt/local/lib/ruby/gems/1.8"]
- :sources => ["http://rubygems.org/", "http://gems.github.com", "http://gems.github.com"]
- REMOTE SOURCES:
- http://rubygems.org/
- http://gems.github.com
- http://gems.github.com
Gem.path in irb points to
/Users/grautur/.gem/ruby/1.8
/usr/local/lib/ruby/gems/1.8
Gem.path in ruby points to
/Users/grautur/.gem/ruby/1.9.1
/usr/local/lib/ruby/gems/1.9.1
I'm not sure what's going on. However, the following may help.
In irb, do
require 'rubygems'
require 'mygem'
puts $:
and then, in ruby, do
require 'rubygems'
puts $:
and show us what you get if you haven't worked it out.
Edit: also print out the results of doing gem env on the command line.
Edit 2: See what happens if you type in puts Gem.path after you've required rubygems in both irb and ruby. See thanks to Matt for describing Rubygems
You may try to add gem 'mygem' before the require, but that should not be necessary.
You will have to add gem install mygem in your Gamefile and then run bundle install command. Your application will work correctly after doing this.
I had a similar problem. The solution I found eventually was to setup rvm (ruby version manager) on my system and use it to setup a new ruby environment. it also makes it easy to switch between ruby versions of sets of gems.

Problem requiring the RMagick gem with Ruby

I installed RMagick on a Windows system with no apparent problems, but I'm having problems actually using it. In particular:
C:\Users\dancrumb> ruby -rubygems -rRMagick -e "puts Magick::Long_version"
C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb:900:in `report_activate_error':
RubyGem version error: rmagick(2.12.0 not >= 0) (Gem::LoadError)
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb:248:in `activate'
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb:212:in `rescue in try_activate'
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb:209:in `try_activate'
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:57:in `rescue in require'
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
The main sticking block is the seemingly illogical error message: RubyGem version error: rmagick(2.12.0 not >= 0). Unless I'm missing something, 2.12.0 is most definitely greater than 0.
Some useful information:
C:\Users\dancrumb>gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.6.2
- RUBY VERSION: 1.9.2 (2010-12-25 patchlevel 136) [i386-mingw32]
- INSTALLATION DIRECTORY: C:/Ruby192/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: C:/Ruby192/bin/ruby.exe
- EXECUTABLE DIRECTORY: C:/Ruby192/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- C:/Ruby192/lib/ruby/gems/1.9.1
- C:/Users/dancrumb/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
C:\Users\dancrumb>dir \Ruby192\lib\ruby\gems\1.9.1\gems
Volume in drive C is TI106036W0F
Volume Serial Number is 4432-A499
Directory of C:\Ruby192\lib\ruby\gems\1.9.1\gems
...
03/26/2011 01:34 PM <DIR> rmagick-2.12.0-x86-mswin32
...
03/20/2011 08:06 PM <DIR> rubygems-update-1.6.2
...
The supplied README file and the forums associated with RMagick don't afford any insight.
It gets weirder:
C:\Users\dancrumb>ruby -rubygems -e "gem 'rmagick', '2.12.0'; puts Magick::Long_
version"
C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb:900:in `report_activate_error':
RubyGem version error: rmagick(2.12.0 not = 2.12.0) (Gem::LoadError)
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb:248:in `activate'
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb:1276:in `gem'
from -e:1:in `<main>'
As well as the specific question on RMagick, can anyone provide me with a sensible interpretation of the version error... it seems nuts to me, but maybe it is actually conveying something useful... just in a nutso way.
I had the very same problem in Ruby 1.8.7 as you with 1.9.1. This is a way I've resolved it:
Uninstall the rmagick gem if you have it (gem uninstall rmagick)
Download http://rubyforge.org/frs/download.php/64917/RMagick-2.12.0-ImageMagick-6.5.6-8-Q8.zip
Unpack the zip to separate folder (e.g. C:\temp\rmagick)
Install the ImageMagick-6.5.6-8-Q8-windows-dll.exe
Unpack the rmagick-2.12.0-x86-mswin32.gem to separate folder (e.g. C:\temp\rmagick\gem)
Extract the data.tar.gz to separate folder (e.g. C:\temp\rmagick\gem\data)
Open rmagick.gemspec and remove the line with s.platform = "mswin32"
Use "gem build rmagick.gemspec" to build the gem again (a "rmagick-2.12.0.gem" will be generated)
Use "gem install rmagick --local" to install it.
Type the following:
ruby --version
If its output is something like
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
it means the Ruby was built using mingw32, which was not supported by the RMagick.
Though README.html of RMagick-2.12.0-ImageMagick-6.5.6-8-Q8 package says
Ruby 1.8.6, installed via the One-Click Installer.
in the prerequisites, the latest One-Click Installer is built using mingw32, and that causes the trouble.
Looking at the source code for rubygems, it looks like rmagick might be responding incorrectly to rubygems' queries about its version for some reason; not sure what.
When you don't supply a specific version number, rubygems will fall back on >= 0 as its version_requirements.
Try this instead, to be more explicit, and so the versions match exactly:
ruby -rubygems -e "gem 'rmagick', '2.12.0'; puts Magick::Long_version"

Resources