http://bjoernstechblog.rueffer.info/posts/ruby-gems/2015/05/20/Setting-up-ruby-gems/
last updated on 25 May 2018

20 May 2015

How I set up my ruby environment (on a Mac/Yosemite)

This post is a little memory aid for myself, as I repeatedly had the problem of having to re-set up my ruby/gems/bundler environment. I need this mainly to run jekyll.

The key is to get the shell environment set up correctly and to install bundler. Bundler then takes care of setting up jekyll and its dependencies based on an appropriate Gemfile that resides in the root directory for my homepage. In that directory I only have to say bundle and everything happens automatically from there, at least as long as the above mentioned prerequisites are met.

The first thing is to look at the ruby environment:

$gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.14
  - RUBY VERSION: 2.0.0 (2014-05-08 patchlevel 481) [universal.x86_64-darwin14]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-14
  - GEM PATHS:
     - /Library/Ruby/Gems/2.0.0
     - /Users/bjoern/.gem/ruby/2.0.0
     - /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/

As you can see, INSTALLATION DIRECTORY points to some location in my file system maintained by the operating system. I do not want to mess with that. So this is what needs to be adapted:

$grep -i gem ~/.profile
# Ruby gems
export GEM_HOME=~/.gem/ruby/2.0.0
export PATH=$PATH:~/.gem/ruby/2.0.0/bin

GEM_HOME is the place where gems will now install gems. I chose that location because it was already in my home folder. The adaptation to PATH ensures that I can call bundler as bundler from the command line. I don’t know of any alternatives (other than using an explicit path to the executable). The result is the intended one:

$gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.14
  - RUBY VERSION: 2.0.0 (2014-05-08 patchlevel 481) [universal.x86_64-darwin14]
  - INSTALLATION DIRECTORY: /Users/bjoern/.gem/ruby/2.0.0
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/bjoern/.gem/ruby/2.0.0/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-14
  - GEM PATHS:
     - /Users/bjoern/.gem/ruby/2.0.0
     - /Library/Ruby/Gems/2.0.0
     - /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
Björn Rüffer — Copyright © 2009–2018 — bjoern.rueffer.info