Skip to content

CLI Commands

The rubygems CLI uses Go's flag package — pass one subcommand flag plus its arguments.

One subcommand flag selects the action; global flags (-gem, -query, -mirror, -json, -cache) shape the request and output.

Global flags

FlagDefaultPurpose
-gem NAME""Gem name (for -get, -versions, -deps, -rdeps).
-query QUERY""Search query (for -search).
-limit N10Cap on result rows.
-mirror MdefaultMirror: default, ruby-china, tsinghua, aliyun.
-jsonfalseOutput as JSON.
-cachefalseEnable in-memory caching.
-helpfalseShow usage.

Subcommands

-get — package info

bash
rubygems -get -gem rails
rubygems -get -gem rails -json

Prints the gem's name, version, authors, downloads, source URI, etc.

-search — search packages

bash
rubygems -search -query "http client" -limit 5

Lists matching gems (name + summary), capped at -limit.

-versions — version list

bash
rubygems -versions -gem rails -limit 5

Lists the most recent versions (number, platform, prerelease flag), latest first.

-deps — dependencies

bash
rubygems -deps -gem rails

Shows what rails depends on (and what depends on it), split into runtime/development.

-rdeps — reverse dependencies

bash
rubygems -rdeps -gem rails

Lists gems that depend on rails.

-install — auto-install Ruby

bash
rubygems -install
rubygems -install -force
rubygems -install -no-dev -no-bundler

Provisions Ruby + RubyGems on this machine via the detected package manager. Install-specific flags:

FlagPurpose
-forceReinstall even if Ruby is already present.
-no-devSkip development headers.
-no-bundlerSkip installing Bundler.
-no-updateSkip the package-index update (apt update, etc.).
-no-sudoDon't use sudo.

See Auto-Install for the programmatic equivalent.

Mirrors

Use -mirror to switch endpoints without changing code:

bash
rubygems -get -gem rails -mirror ruby-china
rubygems -search -query puma -mirror tsinghua
ValueEndpoint
defaulthttps://rubygems.org
ruby-chinahttps://gems.ruby-china.com
tsinghuahttps://mirrors.tuna.tsinghua.edu.cn/rubygems/api
aliyunhttps://mirrors.aliyun.com/rubygems

JSON output

Add -json to any read subcommand to get machine-readable output — handy for piping into jq:

bash
rubygems -get -gem rails -json | jq '.downloads'

Next: Examples.

Released under the MIT License.