Rubygems needs a shared gem cache
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
Just forked rubygems to add that feature : https://github.com/zimbatm/rubygems/tree/feature%2Fshared-cache
WARN: Things are too fresh to stable ;-)
@zimbatm: Status?
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.
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.
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
Is this still relevant now that it's all Go?
It's more related to the layout_ruby stdlib function but maybe issues should get closed when not worked on.
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.