Gem loads in irb but not console
Solution 1
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.
Solution 2
Make sure that you require it in your Gemfile and do a bundle install.
Edit - Try requiring rubygems, then nokogiri.
lambinator
Updated on June 04, 2022Comments
-
lambinator almost 2 years
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.
-
lambinator over 13 yearsGemfile already contains an entry for gem 'nokogiri' and bundle install completes successfully.
-
Chris Johnsen over 13 yearsMy guess is also a case problem that “disappears” in the case-insensitive Windows environment. I suggest the OP try
grep -FR Nokogiri .
(from the root of the application) to try to find the uppercase mention(s). -
lambinator over 13 yearsThank you both, it was a casing problem.. that's taking some getting used to. :)
-
MadCoder about 9 yearsThe edit part helped when I was trying to load gem via irb (without any rails project)