我将slim
gem安装到我自己的自定义目录中,但需要“瘦身”#39;给我错误。
安装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_PATH添加了/var/www/project/gems
):
$ 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/
测试:
$ 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>'
知道什么是错的吗?我在GEM_PATH中添加了/var/www/project/gems
但require 'slim'
没有加载宝石,为什么会这样?这是rubygems的错误吗?
我在require 'slim'
和/var/www/project/index.rb
中撰写ruby index.rb
时遇到同样的问题。
答案 0 :(得分:3)
我衷心建议使用bundler,它不仅可以管理此版本,还可以代表您进行版本固定和部署。
相关的调用将是;在Gemfile
source :rubygems
gem "slim"
然后
gem install bundler && bundle install && bundle exec irb
此时require 'slim'
将起作用。
答案 1 :(得分:1)
由于您在/var/www/project/gems/
处安装了slim,因此您必须将其添加到加载路径或按完整路径要求:
require '/var/www/project/gems/slim'
或将其添加到您的加载路径:
$LOAD_PATH.unshift(File.dirname('/var/www/project/gems/'))