Another Japan in the World

Jun Aruga's blog, who lived in Japan, Singapore, live in Czech Republic. Mainly about IT and travel.

Gem command

Gem - It is package manager for Ruby, not to mention.

Check "gem" command tightly now.



$ gem -h

Display version

$ gem -v

Update gem itself.

$ gem update --system
Display change log.

$ gem -v

Environment variables

$ gem env

Listing for local, remote

Check local, remote gems.
Can use regular expressions for searching string.
Below 3 commands looks same. Can search for both local (--local) and remote (--remote)

  • "gem list"
  • "gem query"
  • "gem search"
$ gem list "^action"

*** LOCAL GEMS ***

actionmailer (4.2.6)
actionpack (4.2.6)
actionview (4.2.6)
$ gem list "^rspec$" --remote


rspec (3.4.0)

Search file on local

Check install directory for the gem.

$ gem contents rspec --show-install-dir

Search file path for the specified file.

$ gem which rspec

$ gem which rails

Open installed gem file directly by the editor (vi, and etc)

$ gem open rspec

Check files in the gem file.

$ gem fetch rspec
Fetching: rspec-3.4.0.gem (100%)
Downloaded rspec-3.4.0

$ ls

$ gem unpack rspec-3.4.0.gem
Unpacked gem: '... rspec-3.4.0'

$ ls

Case: update one gem to latest version.

$ gem list rubocop

*** LOCAL GEMS ***

rubocop (0.36.0)
$ gem list "^rubocop$" --remote


rubocop (0.39.0)

Install. In this case, only one version is existed on remote gem.
So, if do not specify the version, install the version.

$ gem install rubocop -r 0.39.0

$ gem install rubocop
$ gem list rubocop

*** LOCAL GEMS ***

rubocop (0.39.0, 0.36.0)

Uninstall old version.

$ gem cleanup rubocop
Cleaning up installed gems...
Attempting to uninstall rubocop-0.36.0
Successfully uninstalled rubocop-0.36.0
Clean Up Complete
$ gem list rubocop

*** LOCAL GEMS ***

rubocop (0.39.0)
Remove all ads