Soroush Rabiei
Soroush Rabiei

Reputation: 10868

Ruby gem fails to load

I've installed a gem from command line:

sudo gem install jalalidate

gem says it's installed:

$ gem list jalalidate
*** LOCAL GEMS ***

jalalidate (0.3.2)

And it can be loaded:

ruby -rubygems -e 'require "jalalidate"' # output is empty, (success?)

Though when I try to include this gem in a Rakefile, rake fails:

# Rakefile:
require "rubygems"
require "bundler/setup"
require "stringex"
require "jalalidate"

# Terminal:
$ rake new_post["title"]
rake aborted!
cannot load such file -- jalalidate

(See full trace by running task with --trace)

Note:

Update:

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.11
  - RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [x86_64-linux]
  - INSTALLATION DIRECTORY: /var/lib/gems/1.9.1
  - RUBY EXECUTABLE: /usr/bin/ruby1.9.1
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /var/lib/gems/1.9.1
     - /home/soroush/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

Upvotes: 0

Views: 839

Answers (2)

matt
matt

Reputation: 79723

Your Rakefile has require "bundler/setup" before you try to require jalalidate which means you are using Bundler and so you have a Gemfile, which is restricting the gems (and versions) available.

In order to use the gem in your project, add the line

gem "jalalidate"

to the Gemfile.

Upvotes: 1

Mark Joseph Jorgensen
Mark Joseph Jorgensen

Reputation: 115

See this question about why using sudo with gem commands is mostly a bad idea.

I recommend trying to install the gem without sudo: gem install jalalidate

Upvotes: 0

Related Questions