Library message "Missing file" required
I have a small application that I created with the help of a jeweler. The jeweler generates a lib / directory where I suppose he should write his code.
This gem I'm creating depends on the httparty gem, so in my Rakefile I put
Jeweler::Tasks.new do |gem|
gem.add_dependency('httparty', '>= 0.4.5')
...
end
in my implementation file i put
require 'httparty'
but when i execute it i get:
lib / my_app.rb: 1: in `require ': no such file to load - httparty (LoadError)
I have already installed the httparty gem using
sudo gem install httparty
What is missing?
source to share
If you do
require "httparty"
ruby searches different places for httparty.rb or httparty.so. Where is the search for rubies and in what order are they stored in the global variable $:
On my debian system it looks like this:
$: # => ["/usr/local/lib/site_ruby/1.8", "/usr/local/lib/site_ruby/1.8/x86_64-linux", "/usr/local/lib/site_ruby", "/usr/lib/ruby/vendor_ruby/1.8", "/usr/lib/ruby/vendor_ruby/1.8/x86_64-linux", "/usr/lib/ruby/vendor_ruby", "/usr/lib/ruby/1.8", "/usr/lib/ruby/1.8/x86_64-linux", "."]
But httparty.rb is located in / var / lib / gems / 1.8 / gems / httparty-0.4.5 / lib / httparty.rb, so it cannot be found. When you do
require "rubygems"
The # core requires the method to be changed to find the rubygems.
requires "rubygems", which makes your platform code dependent:
- Someone might install your library in a different way than rubygems
- Some Linux distributions (like gentoo) make the "rubygems" requirement unnecessary
On my debian systems, I link each rubygems library to / usr / local / lib / site_ruby / 1.8 /, this path is included in the standard search path ($ :). You can find out about this at http://tomayko.com/writings/require-rubygems-antipattern .
source to share
Some people do not consider it good practice to require Rubygems in redistributable code. The solution is a must require rubygems
before loading your own new gem from your application code. (you will have to do it anyway)
source to share
This error can occur when trying to make HTTP messages with Ruby, but did not complete the Rubygems and RVM setup.
-
First check if rubygems and rubygems-update are installed correctly with the tutorial: http://docs.rubygems.org/read/chapter/3
-
If you are using RVM you also need to create a gemset and select the ruby version first.
$ rvm gemset list
If this shows you are enabled (by default) then you need to configure your RVM.
Find the ruby version you want to use ($ ruby -v) will work and substitute it here:
$ rvm use 1.9.2-head@albinochipmunk --create
- Once your rubigem is installed and your RVM has gemset and ruby version selected, you should be able to install httparty without sudo:
$ gem install httparty
Installing httparty with sudo can break the RVM configuration, so you want to avoid it. Also, using the new Gemset RVM will mean that you may need to reinstall some gems.
source to share