direnv icon indicating copy to clipboard operation
direnv copied to clipboard

Rubygems needs a shared gem cache

Open zimbatm opened this issue 14 years ago • 8 comments

I'm tired of downloading the same gems over and over again because they have a different GEM_HOME.

GEM_CACHE should be settable (or a smarter heuristic), separated from the GEM_HOME

zimbatm avatar May 28 '11 21:05 zimbatm

Just forked rubygems to add that feature : https://github.com/zimbatm/rubygems/tree/feature%2Fshared-cache

WARN: Things are too fresh to stable ;-)

zimbatm avatar Jun 05 '11 11:06 zimbatm

@zimbatm: Status?

pwaller avatar Jun 16 '13 19:06 pwaller

This need much more work. It's not a requirement for direnv but would make ruby and direnv work nicer together so I'm just leaving it here now.

zimbatm avatar Jun 16 '13 20:06 zimbatm

If you're using Bundler, this is a non-issue. See https://gist.github.com/nyarly/4774570 - which is one of the use cases I was looking to replace with direnv.

The upshot is that Bundler installs all gems to one directory, and isolates which ones are loaded.

nyarly avatar Jan 29 '14 21:01 nyarly

You can also set the BUNDLE_BIN environment variable and bundler will start generating binstubs to that path. Right now the layout ruby function also sets the GEM_HOME but it could be stripped out: https://github.com/zimbatm/direnv/blob/direnv-exec/cmd_stdlib.go#L252

zimbatm avatar Jan 30 '14 11:01 zimbatm

Is this still relevant now that it's all Go?

pwaller avatar Sep 29 '15 14:09 pwaller

It's more related to the layout_ruby stdlib function but maybe issues should get closed when not worked on.

zimbatm avatar Sep 29 '15 14:09 zimbatm

Shouldn't the following do the trick without the need to modify direnv itself?

# .config/direnv/lib/ruby.sh
use_ruby() {
  local ruby=$1
  load_prefix ~/.rubies/$ruby
  layout ruby
  unset GEM_HOME
  export GEM_HOME=~/.gem/${ruby%-*}/$(basename $(gem env gemdir))
  PATH_add $GEM_HOME/bin
  PATH_add bin
}

For Ruby 3.1.1, this sets the GEM_HOME to something like ~/.gem/ruby/3.1.0 (patchlevel is ignored). It adds the corresponding bin to the path and finally the local bin as well (in order to use the binstubs without having to type the bin/ prefix.

svoop avatar Feb 19 '22 15:02 svoop