GEM_HOME 和 GEM_PATH 有什么区别?

RubyGems 是 Ruby 编程语言的一个包管理器,它提供了一个分发 Ruby 程序和库的标准格式(以一种称为“ gem”的自包含格式) ,一个用于轻松管理 gems 安装的工具,以及一个用于分发它们的服务器。它类似于 Python 的 EasyInstall。RubyGems 现在是 Ruby 1.9版标准库的一部分。

也就是说,GEM _ HOME 和 GEM _ PATH 之间的区别是什么?

45466 次浏览

GEM_PATH provides the locations (there may be several) where gems can be found.

GEM_HOME is where gems will be installed (by default).

(Therefore GEM_PATH should include GEM_HOME).

Also interesting notice. At least on Wndows XP, don't know about other platforms.

Set GEM_HOME in Windows:

C:\>set GEM_HOME=C:\sbox\ruby\dump\.gems

Now let's check this.

1) In Windows ENVs. All OK, as expected:

C:\>set
...
GEM_HOME=C:\sbox\ruby\dump\.gems
...

2) With gem env. Notice it puts GEM_HOME along with GEM_PATHs but at the first place:

C:\>gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.3
- RUBY VERSION: 2.0.0 (2013-02-24 patchlevel 0) [i386-mingw32]
- INSTALLATION DIRECTORY: C:/sbox/ruby/dump/.gems
- RUBY EXECUTABLE: C:/Ruby200/bin/ruby.exe
- EXECUTABLE DIRECTORY: C:/sbox/ruby/dump/.gems/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- C:/sbox/ruby/dump/.gems
- C:/Documents and Settings/User/.gem/ruby/2.0.0
- C:/Ruby200/lib/ruby/gems/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/

3) Now with bundle env:

C:\>bundle env
Bundler 1.3.4
Ruby 2.0.0 (2013-02-24 patchlevel 0) [i386-mingw32]
Rubygems 2.0.3
GEM_HOME C:\sbox\ruby\dump\.gems
GEM_PATH

GEM_PATH is empty, it means default value. But from where does it take the default value? See gem env.