This website uses cookies. If you continue to use this site we will assume that you are happy with this. When you close this box we will save this information in a cookie to ensure you'll never be bothered with this information box. ×


Gems

Gem, in general, is a Ruby software package with standardized format. You may consider it as an additional software library, which gives an extention to standard Ruby package. Most of the Gems are kept in the RubyGems.org hosting service: https://rubygems.org. They are created by the community and everyone can build and post his own Gem. Of course, it is not mandatory to use the RubyGems.org, but it is the most convinient way to extend the Ruby.

With Ruby it comes another command line tool - gem - "a sophisticated package manager for the Ruby programming language". Like the other software package managers it allows to search, install and uninstall and create your own Gems.

To see installed packaged, use gem list. You can see a list of Gems and their versions installed on the current Ruby version. If you are using rbenv or RVM, this list depends on which Ruby installation are you currently using!

$ gem list

*** LOCAL GEMS ***

bigdecimal (1.2.0)
io-console (0.4.2)
json (1.7.7)
minitest (4.3.2)
psych (2.0.0)
rake (0.9.6)
rdoc (4.0.0)
test-unit (2.0.0.0)


Searching for Gems
$ gem search --remote --details *rot13$

*** REMOTE GEMS ***

crypt-rot13 (1.0.5)
    Author: Daniel J. Berger
    Homepage: http://www.rubyforge.org/projects/shards

    Character rotation encryption, i.e. Caesar Cipher

rot13 (0.1.3)
    Author: James Robertson
    Homepage: https://github.com/jrobertson/rot13

    ROT13 is a simple letter substitution cipher; see
    http://en.wikipedia.org/wiki/ROT13


Installing Gems

Installing Gems is like installing the other software packages - with gem install command. This solves the dependencies, downloads the required package and installs it - everything with this one command. It installs the documentation for fetched Gems as well.

$ gem install rot13
Fetching: rot13-0.1.3.gem (100%)
Successfully installed rot13-0.1.3
Parsing documentation for rot13-0.1.3
Installing ri documentation for rot13-0.1.3
1 gem installed


Using Gems

Now you can use freshly installed Gem. There is no need to know where the package is installed, Gems are installed in the well-known path, under the current Ruby version. You can load the freshly installed gem with require 'rot13' statement and use it - in the example below run Rot13#rotate method:

irb(main):001:0> require 'rot13'
=> true
irb(main):003:0> Rot13.rotate('Rkgerznyl hfrshy ba Hfrarg')
=> "Extremaly useful on Usenet"


Uninstalling Gems

To uninstall the gem, run gem uninstall command. If you have more than one version of the Gem, you must specify which one you want to delete using the --version switch or use the interactive mode:

$ gem uninstall rot13

Select gem to uninstall:
 1. rot13-0.1.2
 2. rot13-0.1.3
 3. All versions
> 3
Successfully uninstalled rot13-0.1.2
Successfully uninstalled rot13-0.1.3