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.
Related
I can't figure out why rubygems is unable to find sinatra on the require "sinatra" line in the following code. I've tried to write the ruby to ensure that sinatra is installed..
Ruby
$:.push("/home/xxxx/ruby/gems")
require 'rubygems'
begin
gem "sinatra"
rescue LoadError
system("gem install sinatra")
Gem.clear_paths
end
require 'sinatra'
get "/" do
"Hello, world!"
end
Error - on line: require 'sinatra'
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- sinatra (LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
I'm running the script through SSH with the bash command 'ruby app.rb', if that's relevant.
Gem env returns: (where /home/xxxx/ruby/gems is the correct location of the gems)
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.25
- RUBY VERSION: 1.8.7 (2012-06-29 patchlevel 370) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/xxxx/ruby/gems
- RUBY EXECUTABLE: /usr/bin/ruby
- EXECUTABLE DIRECTORY: /home/xxxx/ruby/gems/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/xxxx/ruby/gems
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "gempath" => []
- "gem" => "--remote --gen-rdoc --run-tests"
- "rdoc" => "--inline-source --line-numbers"
- "gemhome" => "/home/xxxx/ruby/gems"
- REMOTE SOURCES:
- http://rubygems.org/
I would recommend using bundler.
First, gem install bundler on both your dev machine and on the server.
Next create a file named Gemfile which contains something like this:
source "https://rubygems.org"
gem "sinatra"
# add a "gem" line for any other gems your application needs
(The command bundle init will create a skeleton Gemfile for you).
Then you do a "bundle install" to install the gems. This will create a "Gemfile.lock" file which gives the exact version of each gem. That file gets checked into your version control along with the Gemfile.
Once that code has been distributed to the server, then "bundle install" on the server to get the exact same gems installed there.
In your application, do not:
require "rubygems"
Modify $:
Install missing gems
On the server where you want to run your application, instead of just ruby app, you will run bundle exec ruby app.
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.
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.
This one is driving me nuts. I can load a gem via irb:
steve#server:/var/www/listings$ irb
irb(main):001:0> Gem.path
=> ["/home/steve/.gem/ruby/1.9.1", "/usr/local/ruby/lib/ruby/gems/1.9.1"]
irb(main):002:0> require 'nokogiri'
=> true
But I can't load it through the rails console:
irb(main):001:0> Gem.path
=> ["/home/steve/.gem/ruby/1.9.1", "/usr/local/ruby/lib/ruby/gems/1.9.1"]
irb(main):002:0> require 'nokogiri'
=> false
The gem (nokogiri) is installed
steve#server:/var/www/listings$ gem which nokogiri
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/nokogiri.rb
And bundle agrees
steve#server:/var/www/listings$ bundle show nokogiri
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1
But, of course, rake spec fails with
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:304:in `rescue in depend_on': No such file to load -- Nokogiri (LoadError)
Other environment info:
steve#server:/var/www/listings$ ruby --version
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
steve#server:/var/www/listings$ rails --version
Rails 3.0.1
steve#server:/var/www/listings$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [i686-linux]
- INSTALLATION DIRECTORY: /usr/local/ruby/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /usr/local/ruby/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/ruby/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /usr/local/ruby/lib/ruby/gems/1.9.1
- /home/steve/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Any suggestions??
Edit
By the way, Nokogiri is in the Gemfile and bundle install completes without complaint.
This is a project I'm moving from windows to Ubuntu. On windows it's working fine (oddly enough!) so I'm pretty sure it's an environment thing.
require returns false if that file has already been loaded. Try it out in your irb session by performing the require statement twice in a row. The second one will return false:
irb(main):001:0> require 'nokogiri'
=> true
irb(main):002:0> require 'nokogiri'
=> false
If the file could not be found, require will raise a LoadError instead.
Your exception message (No such file to load -- Nokogiri), makes it seem like something is requiring 'Nokogiri' instead of 'nokogiri', which might be a problem on a case-sensitive operating system.
Make sure that you require it in your Gemfile and do a bundle install.
Edit - Try requiring rubygems, then nokogiri.
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?