Last Updated: August 28, 2017
·
11.27K
· zwaldowski

Sudoless, brewed rubygems on OS X

brew install rbenv ruby-build

Upgrade gem so it honors the bindir:

sudo gem update --system

Add to your ~/.zshrc or ~/.bash_profile:

export RBENV_ROOT="$(brew --prefix rbenv)"
export GEM_HOME="$(brew --prefix)/opt/gems"
export GEM_PATH="$(brew --prefix)/opt/gems"

Or your fish_config:

set -x RBENV_ROOT (brew --prefix rbenv)
set -x PATH $RBENV_ROOT/bin $PATH
set -x PATH $RBENV_ROOT/shims $PATH

set -x GEM_HOME (brew --prefix)/opt/gems
set -x GEM_PATH (brew --prefix)/opt/gems

And finally your ~/.gemrc:

gem: -n/usr/local/bin

You might also want to update gem again for the brewed install. (So without sudo.)

Bonus points for upgrading ruby:

rbenv install 2.0.0-p195
rbenv global 2.0.0-p195

Resulting in:

~ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.3
  - RUBY VERSION: 2.0.0 (2013-05-14 patchlevel 195) [x86_64-darwin12.3.0]
  - INSTALLATION DIRECTORY: /usr/local/opt/gems
  - RUBY EXECUTABLE: /usr/local/opt/rbenv/versions/2.0.0-p195/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/opt/gems/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-12
  - GEM PATHS:
     - /usr/local/opt/gems
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "-n/usr/local/bin --no-rdoc --no-ri"
  - REMOTE SOURCES:
     - https://rubygems.org/

Alternatively, in a certain surf-oriented release (or better), Ruby 2.0 is already installed. Use the gemrc, GEM_HOME, and GEM_PATH changes along with this hack (probably only necessary in Seed 1):

sys_rb_usr=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr
sdk_rb_usr=`xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr
sudo cp -r $sdk_rb_usr/include $sys_rb_usr/include

1 Response
Add your response

Do not forget to add the rbenv init to your .bash_profile as described here: https://github.com/rbenv/rbenv

over 1 year ago ·