我在我的环境中使用一些本地安装的 gem,我想将路径更改EXECUTABLE DIRECTORY
为~/.gem/bin
我怎样才能实现这个目标?
$gem env
- RUBYGEMS VERSION: 2.2.2
- RUBY VERSION: 2.1.5 (2014-11-13 patchlevel 273) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/flyer/.gem/ruby
- RUBY EXECUTABLE: /usr/bin/ruby
- EXECUTABLE DIRECTORY: /home/flyer/bin
- SPEC CACHE DIRECTORY: /home/flyer/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/flyer/.gem/ruby
- /usr/share/gems
- /usr/local/share/gems
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/bin
- /usr/local/sbin
- /usr/bin
- /usr/sbin
- /bin
- /sbin
- /home/flyer/.local/bin
- /home/flyer/bin
- /home/flyer/.local/bin
- /home/flyer/bin
答案1
如果你的目的是安装 gems 的可执行文件到~/.gem/bin
,您可以设置~/.gemrc
:
gem:
--bindir ~/.gem/bin
# any other gem settings like:
--no-ri --no-rdoc
它不会改变EXECUTABLE DIRECTORY
,但 gems 的可执行文件将被安装到~/.gem/bin
。你可以检查它是否已设置:
$ gem env
- GEM CONFIGURATION:
- "gem" => "--bindir ~/.gem/bin --no-ri --no-rdoc"
为了能够调用它们,请将该目录添加到PATH
.
答案2
你可以试试
$ export GEM_HOME = ~/.gem
这会将您的 gem 可执行目录更改为~/.gem/bin
$ gem env
您可以通过再次运行来确认
如果有效,你可以export GEM_HOME=$HOME/.gem
在文件末尾添加 .bashrc 或 .zshrc来使其永久生效
希望有帮助!
答案3
以下是.bashrc / .zshrc
:
#Ruby + GEM
export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH
此后,我的所有宝石都开始发挥作用。