$ GEM_HOME被`gem install`忽略

时间:2019-03-09 05:50:56

标签: ruby rubygems environment-variables

我已设置$GEM_HOME,但是gem install仍在安装到默认的~/.gem目录。

This rubygems issue说要删除--user-install中的.gemrc选项,但是我没有.gemrc文件。

如何获得gem install以兑现$GEM_HOME的价值?


在这里,我首先删除~/.gem,然后显示它是自动创建的:

% rm -rf ~/.gem
% find ~ -name '*gemrc*'    
% # No output, so .gemrc doesn't exist
% echo $GEM_HOME
/home/ravi/.local/share/gem
% gem install neovim
Building native extensions. This could take a while...
Successfully installed msgpack-1.2.7
Successfully installed multi_json-1.13.1
Successfully installed neovim-0.8.0
Parsing documentation for msgpack-1.2.7
Installing ri documentation for msgpack-1.2.7
Parsing documentation for multi_json-1.13.1
Installing ri documentation for multi_json-1.13.1
Parsing documentation for neovim-0.8.0
Installing ri documentation for neovim-0.8.0
Done installing documentation for msgpack, multi_json, neovim after 0 seconds
3 gems installed
% ls -ld ~/.gem
drwxr-xr-x 1 ravi ravi 8 Mar  9 12:34 /home/ravi/.gem/

环境信息:

% gem --version
3.0.2
% gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 3.0.2
  - RUBY VERSION: 2.6.1 (2019-01-30 patchlevel 33) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/ravi/.local/share/gem
  - USER INSTALLATION DIRECTORY: /home/ravi/.gem/ruby/2.6.0
  - RUBY EXECUTABLE: /usr/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /home/ravi/.local/share/gem/bin
  - SPEC CACHE DIRECTORY: /home/ravi/.cache/gem
  - SYSTEM CONFIGURATION DIRECTORY: /etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/ravi/.local/share/gem
     - /usr/lib/ruby/gems/2.6.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--user-install"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/ravi/.gem/ruby/2.6.0/bin
     - /home/ravi/bin
     - /home/ravi/.local/share/npm/bin
     - /home/ravi/.local/share/go/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/local/sbin
     - /usr/lib/jvm/default/bin
     - /usr/bin/site_perl
     - /usr/bin/vendor_perl
     - /usr/bin/core_perl
     - /usr/lib/systemd
     - /home/ravi/.local/share/miniconda3/bin
     - /home/ravi/.cabal/bin
     - /usr/lib/jvm/default/bin
     - /usr/bin/site_perl
     - /usr/bin/vendor_perl
     - /usr/bin/core_perl
%

1 个答案:

答案 0 :(得分:3)

正如Casper在评论中指出的那样,我的配置仍在从某处获取--user-install

我的~/.gemrc不存在时,我签入/etc/gemrc并发现了以下内容:

# --user-install is used to install to $HOME/.gem/ by default since we want to separate
#                pacman installed gems and gem installed gems
gem: --user-install

要覆盖此问题,我将其添加到了~/.gemrc

gem: --no-user-install

现在$GEM_HOME被尊重。