Skip to content

Commit

Permalink
Use the Ruby directory basename to decide the GEM_HOME (#419)
Browse files Browse the repository at this point in the history
* Use the Ruby name to decide the `GEM_HOME` such that each installed Ruby has its own
  `GEM_HOME`, even if `RUBY_VERSION` is the same for multiple installed Rubies.
* This is particularly important for TruffleRuby, where different releases with the
  same `RUBY_VERSION` might compile C extensions differently, and each release should
  have a different `GEM_HOME`.
  • Loading branch information
eregon authored and postmodern committed Sep 26, 2021
1 parent 6190e36 commit 949412b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
19 changes: 19 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
### 1.0.0

#### Upgrade Notes

* When updating from `chruby` < 1.0 to `chruby` >= 1.0, you will need to
re-install your gems because the gem directories will be different. It is also
recommended to clean old gem directories under `~/.gem` which will no longer
be used to save disk space. To remove them, you can use
`rm -rf ~/.gem/{ruby,jruby,rbx,truffleruby}/[0-9].[0-9].[0-9]`

#### chruby.sh

* Use the installed Ruby directory name for setting `GEM_HOME`. (@eregon)
This guarantees a unique `GEM_HOME` per installed Ruby, even if they have
the same `RUBY_VERSION`. This is important for native extensions, which
might compile differently based on build-time flags such as `--enable-shared`.
This also fixes the bug that the `GEM_HOME` for non-MRI Ruby implementations
was shared even for different releases.

### 0.3.9 / 2014-11-23

#### chruby.sh
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Changes the current Ruby.
* Updates `$PATH`.
* Also adds RubyGems `bin/` directories to `$PATH`.
* Correctly sets `$GEM_HOME` and `$GEM_PATH`.
* Users: gems are installed into `~/.gem/$ruby/$version`.
* Root: gems are installed directly into `/path/to/$ruby/$gemdir`.
* Users: gems are installed into `~/.gem/$ruby_name` (e.g., `~/.gem/ruby-2.6.3` for `~/.rubies/ruby-2.6.3`).
* Root: gems are installed directly into `$ruby_install_dir/$gemdir` (the default).
* Additionally sets `$RUBY_ROOT`, `$RUBY_ENGINE`, `$RUBY_VERSION` and
`$GEM_ROOT`.
* Optionally sets `$RUBYOPT` if second argument is given.
Expand Down Expand Up @@ -218,13 +218,13 @@ If you have enabled auto-switching, simply create a `.ruby-version` file:
### RubyGems

Gems installed as a non-root user via `gem install` will be installed into
`~/.gem/$ruby/X.Y.Z`. By default, RubyGems will use the absolute path to the
currently selected ruby for the shebang of any binstubs it generates. In some
cases, this path may contain extra version information (e.g.
`~/.gem/$ruby_name`. By default, RubyGems will use the
absolute path to the currently selected ruby for the shebang of any binstubs it
generates. In some cases, this path may contain extra version information (e.g.
`ruby-2.0.0-p451`). To mitigate potential problems when removing rubies, you
can force RubyGems to generate binstubs with shebangs that will search for
ruby in your `$PATH` by using `gem install --env-shebang` (or the equivalent
short option `-E`). This parameter can also be added to your gemrc file.
short option `-E`). This parameter can also be added to your `.gemrc` file.

### Integration

Expand Down Expand Up @@ -269,7 +269,7 @@ Select a Ruby:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/hal/.gem/ruby/1.9.3
- /home/hal/.gem/ruby-1.9.3-p392
- /opt/rubies/ruby-1.9.3-p392/lib/ruby/gems/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
Expand Down
2 changes: 1 addition & 1 deletion share/chruby/chruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ EOF
export PATH="${GEM_ROOT:+$GEM_ROOT/bin:}$PATH"

if (( UID != 0 )); then
export GEM_HOME="$HOME/.gem/$RUBY_ENGINE/$RUBY_VERSION"
export GEM_HOME="$HOME/.gem/${RUBY_ROOT##*/}"
export GEM_PATH="$GEM_HOME${GEM_ROOT:+:$GEM_ROOT}${GEM_PATH:+:$GEM_PATH}"
export PATH="$GEM_HOME/bin:$PATH"
fi
Expand Down

0 comments on commit 949412b

Please sign in to comment.