How do I use RVM and create globally available gems?

Ruby on-RailsRubyMacosRubygems

Ruby on-Rails Problem Overview


I'm running Mac OSX 10.6.4 and have installed RVM. Its been great so far, I really love the way it lets me manage having multiple versions of rails and ruby on the same machine without headaches!

However, I don't want to have to install certain gems (such as passenger) for each setup. Is there a way to share gems between gemsets? I have a [email protected] and 1.9.2@rails3, can I have gems such as passenger, mysql, and capistrano installed once and used with all versions?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

There is something called the global gemset, and it is shared between all your gemsets of a certain ruby-version. But you can't share gems between ruby-versions.

However, what you can do is create a list of gems that will be installed automatically when adding a new ruby version. That is described here. In short: edit a file called ~/.rvm/gemsets/global.gems to contain the list of gems you want to be there for each ruby-version.

Hope it helps.

Solution 2 - Ruby on-Rails

With the latest RVM version (1.17.0 and newer) just type:

rvm @global do gem install passenger

or

rvm 1.9.3@global do gem install passenger if you need it only for a specific version of ruby.

Solution 3 - Ruby on-Rails

You can create and use global gemsets with the following commands:

rvm gemset create global
rvm gemset use global

After you've created and execute use for the global gemset simply install gems as usual:

gem install mysql passenger

Solution 4 - Ruby on-Rails

add the the gems you want for every gemset in a "global" rvm gemset name i.e.

rvm 1.9.2@global

then project specific gemsets rvm 1.9.2@myProject will already have you're "default" gems from your global list

Solution 5 - Ruby on-Rails

Create and use a global gem as:

rvm use <ruby version>@global --create

and install gems you want to share between gemsets:

bundle install <gem name>

but these gems can only be shared between gemsets of the same Ruby version.

Solution 6 - Ruby on-Rails

According to the RVM documentation, there are actually a number of "global" gemsets which can be defined at the rvm-wide level, per interpreter, per interpreter version, and finally at a specific patch-level per interpreter. And installed gems cascade from one level to the next.

Solution 7 - Ruby on-Rails

If you need to install a particular gem across multiple rubies you can do:

rvm all do rvm @global do gem install passenger

Solution 8 - Ruby on-Rails

For someone wanna manually trigger install rvm global.gems

rvm gemset import ~/.rvm/gemsets/global.gems

# or

cat ~/.rvm/gemsets/global.gems | xargs gem install

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGiHView Question on Stackoverflow
Solution 1 - Ruby on-RailsnathanvdaView Answer on Stackoverflow
Solution 2 - Ruby on-Railsyas375View Answer on Stackoverflow
Solution 3 - Ruby on-RailsennuikillerView Answer on Stackoverflow
Solution 4 - Ruby on-RailsJustin SolizView Answer on Stackoverflow
Solution 5 - Ruby on-RailsRamiz RajaView Answer on Stackoverflow
Solution 6 - Ruby on-RailsJaseView Answer on Stackoverflow
Solution 7 - Ruby on-RailsAlex SotoView Answer on Stackoverflow
Solution 8 - Ruby on-RailsfangxingView Answer on Stackoverflow