我安装了rbenv
并设置了ruby和gems。现在,如果我运行gem env
,则得到以下结果:
RubyGems Environment:
- RUBYGEMS VERSION: 2.2.2
- RUBY VERSION: 2.1.0 (2013-12-25 patchlevel 0) [x86_64-darwin13.0]
- INSTALLATION DIRECTORY: /Users/myusername/Tools/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0
- RUBY EXECUTABLE: /Users/myusername/Tools/.rbenv/versions/2.1.0/bin/ruby
- EXECUTABLE DIRECTORY: /Users/myusername/Tools/.rbenv/versions/2.1.0/bin
- SPEC CACHE DIRECTORY: /Users/myusername/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-13
- GEM PATHS:
- /Users/myusername/Tools/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0
- /Users/myusername/.gem/ruby/2.1.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/myusername/Tools/.rbenv/versions/2.1.0/bin
- /Users/myusername/Tools/.rbenv/libexec
- /Users/myusername/Tools/.rbenv/plugins/ruby-build/bin
- /opt/local/bin
- /opt/local/sbin
- /Users/myusername/Tools/.rbenv/shims
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /usr/local/bin
- /Users/myusername/Tools/./bin
- /Users/myusername/Tools/.rbenv/bin
好。。除了
SPEC CACHE DIRECTORY
和GEM PATHS
之外,其他所有路径都是自配置的。(所以我真的不想把任何与开发相关的目录直接放在我的用户主文件夹中。)是否有办法在不影响env variables
、ruby
和gem
等的正常功能的情况下灵活地更改这两个rbenv
?谢谢!
最佳答案
实际上我在网上搜索找到了解决办法。
只需在.profile(max os)或.bashrc(linux)中添加以下内容
export GEM_PATH=/Users/myusername/Tools/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0
export GEM_SPEC_CACHE=/Users/myusername/Tools/.rbenv/versions/2.1.0/lib/ruby/gems/specs
确保你放在那里的文件夹存在。然后获取.profile或.bashrc的源代码,或者重新启动终端。现在我的环境是正确的。
参考文献:
https://github.com/rubygems/rubygems/pull/489
关于ruby - <RubyGems>如何更改gem环境设置?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24303180/