How to install gem across all gemsets when using RVM

不羁岁月 提交于 2019-12-05 20:42:14

问题


Is there a way to install a gem across all rubies and gemsets (not just the default or the system ruby) in the system when using RVM?


回答1:


You can execute:

rvm @global do gem install [gem_name]

to install gem globally (per ruby version).

It is not possible to install gem globally for every ruby version.

According to https://rvm.io/gemsets/initial you can define automatically installed gems for every ruby version in file ~/.rvm/gemsets/global.gems. In this file you need to define required gems (one per line) e.g.

bundler
zeus

These gems will be installed each time you add new ruby version to the RVM.




回答2:


You can install to a default, global gemset per ruby interpreter as mentioned here:

https://rvm.io/gemsets/global/

and also this page mentions default gem sets

https://rvm.io/gemsets/using/

And it wouldn't be useful to install a gem to all ruby interpreters due to incompatibilities between rubies.




回答3:


Looking through the RVM docs, I don't see a way to do this specifically. However, you might be able to approximate it via a combination of @global gemsets and gemset copying copying.

Global gemsets provide gems that are available to all gemsets of a given ruby. E.g.:

rvm install 1.9.3
rvm --create 1.9.3@rails3.0
rvm --create 1.9.3@rails3.1
rvm use 1.9.3@global
gem install sqlite3

would create two different gemsets for the 1.9.3 ruby, and the global sqlite3 would be available in both.

Then, once you've done this, you can copy the global gemset to other rubies, and they'd have it available themselves. For example, as a continuation of the above:

rvm install 1.8.7
rvm gemset copy 1.9.3@global 1.8.7@global

and now the sqlite3 gem is available to all 1.8.7 gemsets (assuming I've got the arguments in the right order - I may not, in which case switch 1.9.3 and 1.8.7). It's not quite ideal, since updates to one ruby don't automatically become visible in the others, you'd have to copy to each ruby individually, and I imagine you'd possibly end up clobbering any ruby-dependant global gems you've set up in each. If that last point isn't an issue you foresee being a problem, though, you could probably write up a script to avoid the tediousness implied by the first two points.

Disclaimer: This is put together strictly from reading through the RVM docs, and I haven't actually tried this out. If I got something wrong, I'll be glad to edit the answer to fix it up.



来源:https://stackoverflow.com/questions/8707604/how-to-install-gem-across-all-gemsets-when-using-rvm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!