liveBook · Manning

RubyGems

As explained in The Well-Grounded Rubyist, Fourth Edition

A Ruby gem is a packaged Ruby library or application distributed as a file with a .gem extension.

RubyGems packages and distributes Ruby libraries and applications as .gem files. Ruby installs several gems by default, and installed gems become available for Ruby programs to use. section 1.2.4

Use RubyGems to install packages, resolve dependencies, and load selected libraries:

  • Run `gem install gemname` to download a gem and any required dependencies from rubygems.org; use a local .gem path for a local package, `-l` for local-only operations, or `-r` for remote-only operations. section 1.4.4
  • Load an installed library with `require`, even though its directory is not initially visible in Ruby's load path. section 1.4.4
  • Select a particular installed version with `gem "name", "version"` before requiring or using the library. section 1.4.4
  • Use Bundler to track a project's exact gems and versions, resolve dependencies, and run commands through the resulting bundle. section 1.4.4

Installing and using a library

Installing `prawn` downloads version 2.5.0 and its dependencies. Ruby can then load it with `require "prawn"`; selecting `gem "prawn", "2.2.0"` changes the library directory added to the load path. section 1.4.4

$ gem install prawn

Try the basic package-installation command that starts the RubyGems workflow. section 1.4.4

How The Well-Grounded Rubyist, Fourth Edition covers it

How deep it goes
Explains installation, dependencies, local and remote sources, requiring gems, load paths, and version selection, but defers gem creation.
Examples
Uses Prawn installation, local Ruport packages, version-specific loading, and a Bundler-managed Colorize program.
What it assumes
Assumes basic Ruby command-line use and requires no prior knowledge of gem creation.
What you can do after
Operate the gem command, load installed libraries with require, select versions, and run projects through Bundler.
How it connects
Connects RubyGems with Bundler, dependencies, require, load paths, and Ruby command-line tools.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Rubyist, Fourth Edition. The section links point to the parts of the book it draws on.