← Home

Aligning rubygems + bundler through rubylib environment variable

Put this into your ~/.zprofile (or ~/.profile or whatever makes sense for your shell):

export RUBYLIB=$RUBYLIB:~/.ruby

Source the file:

$ source ~/.zprofile

Put this to ~/.ruby/b.rb

begin
  # should probably check parent directories, too?
  require File.expand_path('../.bundle/environment')
rescue LoadError
  require 'rubygems'
  require 'bundler'
  Bundler.setup
end

Done.

You can now:

$ ruby -rb test/all.rb        # run test/all.rb in the context of your bundle
$ ruby -rubygems test/all.rb  # run test/all.rb in the context of rubygems
blog comments powered by Disqus