我很难在Snow Leopard环境中正确加载宝石。我在'/ usr / local'中安装了ruby和rubygems(来自http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard/说明),我用'gem install gem-name'安装了一些宝石。
我正确地看到了宝石列表:
$ gem list
*** LOCAL GEMS ***
chrisjpowers-iterm_window (0.3.2)
gemcutter (0.3.0)
我可以看到正确安装的宝石:
$ ls /usr/local/lib/ruby/gems/1.8/gems/
chrisjpowers-iterm_window-0.3.2
gemcutter-0.3.0
正确定义了宝石路径:
$ gem env path
/usr/local/lib/ruby/gems/1.8
我在bash配置文件中定义了各种路径:
$ cat ~/.bash_profile
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
export GEM_HOME="/usr/local/lib/ruby/gems/1.8"
export GEM_PATH="/usr/local/lib/ruby/gems/1.8"
export RUBY_LIB="/usr/local/lib/ruby:/usr/local/lib/ruby/site_ruby"
但是当我运行以下脚本时
#!/usr/local/bin/ruby
require 'rubygems'
require 'chrisjpowers-iterm_window'
我收到以下错误
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- chrisjpowers-iterm_window (LoadError)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/local/bin/sp:4
我不知道如何修复它,任何帮助将不胜感激:)
答案 0 :(得分:2)
您需要错误的lib名称。由于GitHub命名空间,gem名为chrisjpowers-iterm_window
,但该库名为iterm_window
:
require 'rubygems'
require 'iterm_window'
lib路径与gem路径不同。 gem路径是安装gem的地方,但lib路径包含加载rubygems后每个已安装gem的lib目录。您应该在该gem的lib目录中看到iterm_window.rb
。