Last Updated: February 25, 2016
·
943
· erol

Using gs for lean rbenv gemsets

I've recently been using https://github.com/soveran/gs as an alternative to rbenv-gemset. It works great to create gem isolation for legacy projects, and works pretty well with Bundler too. With the tweak below, it also makes running bundle exec obsolete.

There's one caveat to the default install: the gs bin path comes after rbenv shims and system binaries. Here's what a sample path looks like:

/usr/local/var/rbenv/shims:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/Erol/Projects/ohm-sequel/.gs/bin:/usr/local/var/rbenv/versions/1.9.3-p448/bin:/usr/local/Cellar/rbenv/0.4.0/libexec:/usr/local/var/rbenv/shims:/Users/Erol/.yadr/bin:/Users/Erol/.yadr/bin/yadr:/Users/Erol/.yadr/bin:/Users/Erol/.yadr/bin/yadr

I resolved this by adding the following snippet to .zshrc (you can add it to .bashrc if you're using bash):

if [ -n "$GS_NAME" ]; then
  GS_BINPATH=$PWD/.gs/bin
  PATH=$GS_BINPATH:${PATH/${GS_BINPATH}\:/}
fi

Now let's try it out:

Erol@Emiya ~/Projects/ohm-sequel (master)$ gs
Erol@Emiya ~/Projects/ohm-sequel (master)$ echo $PATH
/Users/Erol/Projects/ohm-sequel/.gs/bin:/usr/local/var/rbenv/shims:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/var/rbenv/versions/1.9.3-p448/bin:/usr/local/Cellar/rbenv/0.4.0/libexec:/usr/local/var/rbenv/shims:/Applications/Postgres.app/Contents/MacOS/bin:/Users/Erol/.yadr/bin:/Users/Erol/.yadr/bin/yadr:/Users/Erol/.yadr/bin:/Users/Erol/.yadr/bin/yadr
Erol@Emiya ~/Projects/ohm-sequel (master)$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.23
  - RUBY VERSION: 1.9.3 (2013-06-27 patchlevel 448) [x86_64-darwin12.4.0]
  - INSTALLATION DIRECTORY: /Users/Erol/Projects/ohm-sequel/.gs
  - RUBY EXECUTABLE: /usr/local/var/rbenv/versions/1.9.3-p448/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/Erol/Projects/ohm-sequel/.gs/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-12
  - GEM PATHS:
     - /Users/Erol/Projects/ohm-sequel/.gs
     - /usr/local/var/rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1
     - /Users/Erol/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - :sources => ["http://gems.rubyforge.org/", "http://gems.github.com"]
     - "gem" => "--no-ri --no-rdoc"
  - REMOTE SOURCES:
     - http://gems.rubyforge.org/
     - http://gems.github.com