LinuxCommandLibrary

gem

Manage RubyGems packages

TLDR

Search for remote gem(s) and show all available versions

$ gem search [regex] [[-a|--all]]
copy

Install the latest version of a gem
$ gem install [gem_name]
copy

Install a specific version of a gem
$ gem install [gem_name] [[-v|--version]] [1.0.0]
copy

Install the latest matching (SemVer) version of a gem
$ gem install [gem_name] [[-v|--version]] '~> [1.0]'
copy

Update a gem
$ gem update [gem_name]
copy

List all local gems
$ gem list
copy

Uninstall a gem
$ gem uninstall [gem_name]
copy

Uninstall a specific version of a gem
$ gem uninstall [gem_name] [[-v|--version]] [1.0.0]
copy

SYNOPSIS

gem [global-options] command [args] [--] [args]

PARAMETERS

-h, --help
    Display help for the given command

-V, --version
    Display RubyGems version

-q, --quiet
    Silence RubyGems output

-v, --verbose
    Enable verbose output (repeatable for more verbosity)

--config-file FILE
    Use specified config file instead of default

--backtrace
    Show full stacktrace on errors

--debug
    Enable Ruby level debugging

--norc
    Disable loading .gemrc files

--user-install
    Install to user directory (default on non-root)

--no-user-install
    Install to system directory

--source URL
    Gem server hosting path

DESCRIPTION

The gem command is the primary interface to RubyGems, the standard package manager for the Ruby programming language. RubyGems enables developers to discover, install, update, and remove gems—self-contained packages that bundle Ruby code, documentation, and specifications for libraries or applications.

Key functionalities include automatic dependency resolution, support for multiple versions of the same gem, platform-specific binaries, and integration with Ruby's require mechanism. Gems are primarily sourced from the central repository at rubygems.org, but private sources can be configured.

Common workflows involve installing gems with gem install, listing installed ones with gem list, or updating the entire system with gem update --system. User-specific installations (avoiding root privileges) use --user-install. RubyGems handles conflicts, prereleases, and remote queries efficiently, making it essential for Ruby development environments.

CAVEATS

Requires Ruby installation; root privileges needed for system-wide installs. Network access required for remote gems. Verify sources to avoid malicious gems. Bundler recommended for production apps over direct gem use.

COMMON SUBCOMMANDS

install GEM: Install a gem.
list: List installed gems.
update GEM: Update specific gem.
uninstall GEM: Remove a gem.
env: Show environment info.
search NAME: Search remote gems.

CONFIG FILES

~/.gemrc and /etc/gemrc for settings like gem: push_docs: false or sources.

HISTORY

RubyGems originated in 2003 by Rich Kilmer and Chad Fowler as a Ruby library packaging system. Released as gem 0.1 in 2004, it became Ruby's default package manager by Ruby 1.9 (2009). Version 3.0 (2018) introduced stricter security defaults. Maintained by RubyGems.org team under Ruby Core.

SEE ALSO

ruby(1), bundler(1), rake(1)

Copied to clipboard