set GEM_HOME on the environment to avoid inconsistencies
| Task Info (Flyspray) | |
|---|---|
| Opened By | Felipe Contreras (felipec) |
| Task ID | 68757 |
| Type | Feature Request |
| Project | Arch Linux |
| Category | Packages: Extra |
| Version | None |
| OS | All |
| Opened | 2020-11-27 02:38:12 UTC |
| Status | Assigned |
| Assignee | Anatol Pomozov (anatolik) |
Details
The instructions in the wiki to allow user installations of gems mention the --user-install option, but this is ignored by the bundler program.
First, the instructions say to do this to disable building the documentation:
~/.gemrc:
gem: --no-document
But this would override the system's /etc/gemrc, which has --user-install, so the user actually has to do:
~/.gemrc:
gem: --user-install --no-document
Then the instructions proceed to explain --user-install, and that the gems end up in ~/.gems/ruby.
Then the instructions for bundler are mentioned, and the following command is suggested:
bundle config path ~/.gem
However, that's not the same path gem uses (~/.gem/ruby).
The actual path can be found running the command ruby -e 'puts Gem.user_dir' (e.g. ~/.gem/ruby/2.7.0).
So the instructions are wrong.
I and others have contacted the ruby/bundler developers multiple times over the years, and they have refused to fix the issues:
- https://github.com/rubygems/rubygems/issues/4027
- https://github.com/rubygems/bundler/issues/710
- https://github.com/rubygems/bundler/issues/2565
- https://github.com/rubygems/bundler/issues/2667
There is a very simple solution to get around all these problems, just distribute a script for profile.d:
/etc/profile.d/ruby.sh
export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
This way no --user-install is needed: /etc/gemrc can be dropped, and all the instructions for ~/.gemrc and the bundle path config (which is wrong), since bundle uses $GEM_HOME by default.
Additionally, we can modify the PATH so the user doesn't have to:
export PATH="$PATH:$GEM_HOME/bin"
So the instructions about the setup can be removed.
So this fixes everything:
/etc/profile.d/ruby.sh
export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
export PATH="$PATH:$GEM_HOME/bin"