Rogelio J. Samour github twitter linked in working with rails archives
Posted September 23, 2010

I wanted to share briefly on installing global or default gems in your rvm-controlled rubies. So here it is, say you wanted to always have a certain list of gems installed in all versions of ruby that your rvm controls. Right now you’d have to do something like this to install one or more gems in all your rubies:

1
2
3
4
for x in $(rvm list strings)
do
  rvm use $x@global && gem install hitch bundler
done

And the above works great for your existing rubies. However, going forward the best thing to do is to make your ~/.rvm/gemsets/global.gems look like so:

1
2
3
4
bundler
hitch
mysql
rake

Perfecto! Now the next time you install a new ruby version, bundler, hitch, mysql and rake will be available across all gemsets!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ rvm install 1.9.2

[...] blah blah Installing Ruby blah blah [...]

$ rvm use 1.9.2
Using ~/.rvm/gems/ruby-1.9.2-p0
$ gem list

*** LOCAL GEMS ***

bundler (1.0.0)
highline (1.6.1)
hitch (0.6.0)
mysql (2.8.1)
rake (0.8.7)

$

Now you can do the following to retrofit your currently installed rubies:

1
2
3
4
for x in $(rvm list strings)
do
  rvm use $x@global && gem install $(cat ~/.rvm/gemsets/global.gems)
done

For more info on how to get your environment setup to use rvm in all its glory, go here.

Thanks to Tom Preston-Werner for the CSS layout, Webby for the blog renderer, and GitHub Pages for the blog hosting and Les Hill for letting me steal his stuff.