63

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 1.8.7@rails2.3.8 and 1.9.2@rails3, can I have gems such as passenger, mysql, and capistrano installed once and used with all versions?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
GiH
  • 14,006
  • 13
  • 43
  • 56

8 Answers8

70

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.

mpapis
  • 52,729
  • 14
  • 121
  • 158
nathanvda
  • 49,707
  • 13
  • 117
  • 139
  • thanks, you're the only one who actually answered the question. We can't share the gemsets between ruby interpreter versions (ie 1.8.7 and 1.9.2) but the global gemset can be used to share between projects of the same ruby version (ie, gems installed globally for 1.8.7 will be shared among projects using this version). Also, I up-voted ennuikiller's answer because he actually gave the commands for creating the global gemset. – GiH Oct 24 '10 at 15:01
62

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.

rakvium
  • 64
  • 1
  • 7
yas375
  • 3,940
  • 1
  • 24
  • 33
33

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
Nick
  • 11,475
  • 1
  • 36
  • 47
ennuikiller
  • 46,381
  • 14
  • 112
  • 137
4

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

Justin Soliz
  • 2,781
  • 3
  • 25
  • 33
3

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Ramiz Raja
  • 5,942
  • 3
  • 27
  • 39
2

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.

mpapis
  • 52,729
  • 14
  • 121
  • 158
Jase
  • 563
  • 5
  • 12
1

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

rvm all do rvm @global do gem install passenger

Alex Soto
  • 6,167
  • 1
  • 20
  • 7
0

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
Fangxing
  • 5,716
  • 2
  • 49
  • 53