Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<RubyGems> How to change gem environment settings?

I installed rbenv and set up ruby and gems. Now if I run gem env then I got the following:

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

Well.. all looks good except for SPEC CACHE DIRECTORY and GEM PATHS, all others have self-configured paths. (So I really don't want any dev-related directories directly placed in my user home folder.) Is there a way to flexibly change these two env variables without affecting normal functioning of ruby, gem and rbenv etc.?

Thanks!

like image 696
Bruce Avatar asked Jun 19 '14 09:06

Bruce


1 Answers

Actually I searched online and found the solution.

Just put the following in your .profile (Max OS) or .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

Make sure the folder you put there existed. Then source the .profile or .bashrc, or simply restart your terminal. It is tested working now my env is correct.

Reference: https://github.com/rubygems/rubygems/pull/489

like image 121
Bruce Avatar answered Sep 20 '22 02:09

Bruce