Skip to content

Share gems between Ruby minor versions#502

Open
leoarnold wants to merge 1 commit into
asdf-vm:masterfrom
leoarnold:leoarnold/communal-gems
Open

Share gems between Ruby minor versions#502
leoarnold wants to merge 1 commit into
asdf-vm:masterfrom
leoarnold:leoarnold/communal-gems

Conversation

@leoarnold
Copy link
Copy Markdown

ASDF itself treats every install as a separate entity and does not have a concept of sharing data between installs.

Luckily, Rubygems already provides such a concept through Gem.user_dir which holds a value like

/home/johndoe/.gem/4.0.0

There are two features to note here:

  • Since ASDF will usually install everything into the user's home directory (i.e. ~/.asdf/), we can do the same with the Ruby gems (by using ~/.gem) without loss of generality.
  • While RUBY_VERSION changes with every Ruby release, the built-in value RbConfig::CONFIG["ruby_version"] stays the same for all versions of Ruby which are binary compatible. For example, all Ruby releases in the 3.4.X series will have 3.4.0 as the value of RbConfig::CONFIG["ruby_version"].

So, in order to have communal gem homes for binary compatible releases of Ruby, all we need to do is to use Gem.user_dir as GEM_HOME. We set this value at runtime using bin/exec-env

Fixes #119

ASDF itself treats every install as a separate entity and does not
have a concept of sharing data between installs.

Luckily, Rubygems already provides such a concept through
[`Gem.user_dir`](https://github.com/ruby/rubygems/blob/v4.0.12/lib/rubygems/defaults.rb#L103-L109)
which holds a value like

```text
/home/johndoe/.gem/4.0.0
```

There are two features to note here:

- Since ASDF will usually install everything into the user's home
  directory (i.e. `~/.asdf/`), we can do the same with the Ruby gems
  (by using `~/.gem`) without loss of generality.
- While `RUBY_VERSION` changes with every Ruby release, the built-in
  value `RbConfig::CONFIG["ruby_version"]` stays the same for all
  versions of Ruby which are binary compatible. For example,
  all Ruby releases in the `3.4.X` series will have `3.4.0` as the
  value of `RbConfig::CONFIG["ruby_version"]`.

So, in order to have communal gem homes for binary compatible
releases of Ruby, all we need to do is to use `Gem.user_dir` as
`GEM_HOME`. We set this value at runtime using `bin/exec-env`

Fixes asdf-vm#119
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Share gems between Ruby minor versions

1 participant