I installed slim gem to a custom directory of my own but require 'slim' gives me error.

Installing slim:

$ cd /var/www
$ mkdir project
$ cd project/
$ gem install slim -i gems/
Fetching: temple-0.4.0.gem (100%)
Fetching: slim-1.2.2.gem (100%)
Successfully installed temple-0.4.0
Successfully installed slim-1.2.2
2 gems installed
Installing ri documentation for temple-0.4.0...
Installing ri documentation for slim-1.2.2...
Installing RDoc documentation for temple-0.4.0...
Installing RDoc documentation for slim-1.2.2...
$ ls gems/
bin/            doc/            specifications/ 
cache/          gems/           
$ ls gems/gems/
slim-1.2.2  temple-0.4.0
$ ls gems/gems/slim-1.2.2/
benchmarks  CHANGES  lib      Rakefile   slim.gemspec
bin         Gemfile  LICENSE  README.md  test
$ ls gems/gems/slim-1.2.2/lib/
slim  slim.rb

Gem Environment (If you notice I added /var/www/project/gems to GEM_PATH):

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.11
  - RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [x86_64-linux]
  - 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-linux
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/1.9.1
     - /home/john/.gem/ruby/1.9.1
     - /var/www/project/gems
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gempath" => ["/usr/local/lib/ruby/gems/1.9.1", "/home/john/.gem/ruby/1.9.1", "/var/www/project/gems"]
  - REMOTE SOURCES:
     - http://rubygems.org/

Testing:

$ irb
irb(main):001:0> require 'slim'
LoadError: no such file to load -- slim
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from (irb):1
    from /usr/local/bin/irb:12:in `<main>'

Any idea what's wrong ? I added /var/www/project/gems in the GEM_PATH yet require 'slim' won't load the gem, why so ? Is this a bug with rubygems ?

Same problem when i write require 'slim' in /var/www/project/index.rb and ruby index.rb.

有帮助吗?

解决方案

I would heartily recommend using bundler, which will not only manage this but also version pinning and deployment on your behalf.

The relevant invocation would be; in Gemfile

source :rubygems
gem "slim"

And then

gem install bundler && bundle install && bundle exec irb

At which point require 'slim' will work.

其他提示

Since you're installing slim at /var/www/project/gems/ you'll have to add it to the load path or require it by full path:

require '/var/www/project/gems/slim'

or add it to your load path:

$LOAD_PATH.unshift(File.dirname('/var/www/project/gems/'))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top