gpt4 book ai didi

ruby - $GEM_HOME 被 `gem install` 忽略

转载 作者:行者123 更新时间:2023-12-05 03:02:16 28 4
gpt4 key购买 nike

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

This rubygems issue说要删除 .gemrc 中的 --user-install 选项,但我没有 .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
%

最佳答案

我在使用 snap(Ubuntu 软件)安装的 rubygems 时遇到了同样的问题,它默认安装到 ~/.gem。我能够使用 --install-dir 开关更改安装目录

$ gem install --install-dir /path/to/custom/directory foo

但是,后来我在使用安装在非默认目录中的 gem 时遇到了问题。

卸载它并使用 apt 安装解决了所有问题。

$ sudo snap remove ruby
$ sudo apt-get install rubygems

现在,gems 总是安装到 $GEM_HOME。为了仍然将 ~/.gem 作为默认安装位置,请将其添加到您的初始化脚本(例如 ~/.bashrc):

export GEM_HOME=$HOME/.gem
export PATH=$PATH:$GEM_HOME/bin

要覆盖安装位置,您只需在调用 gem install 之前覆盖 GEM_HOME

关于ruby - $GEM_HOME 被 `gem install` 忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55074420/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com