Multiple versions

RubyGems

gem is the package manager of sorts for Ruby modules (called Gems), somewhat comparable to what pacman is to Arch Linux. The gem command will be installed if you followed the installation instructions above.

Running as root

When running gem as root, gems will be installed for everyone on the machine. This has the advantage of simplicity and is the most reliable method, but updating or installing gems without everyone's knowledge (like on a shared server) might cause Ruby applications to break.

When not running gem as root, the gems will be installed into ~/.gem and not affect anyone else, although it might be worth noting that not all gems are happy to be installed in this way and might insist on being installed by root (especially if they have native extensions).

Bundler solves these problems to some extent by packaging gems into your application. See the section below on using bundler.

Updating RubyGems

# gem update --system

Installing a gem

This example installs the MySQL ruby gem:

# gem install mysql

The process can be speeded up somewhat if you don't need local documentation:

# gem install mysql --no-rdoc --no-ri

The gem will now be downloaded, compiled if necessary, and installed.

Bundler

Bundler installs gems (including those with native extensions) directly into your application, which works very well for shared hosting and easy deployment of Ruby On Rails applications for example. Bundler also resolves dependencies as a whole, rather than individually like RubyGems, making things a lot easier.

It might be a good idea to install bundler as a system-wide gem so everyone can use it:

# gem install bundler

To start a new bundle:

# bundle init

Then add your required gems into "Gemfile" in the current directory (created by bundle init):

gem "rails", "2.3.4"
gem "mysql"

Finally, run the following to install your gems. They will all be installed locally into ~/.bundle, eliminating the need for root access: