Gem command
Gem - It is package manager for Ruby, not to mention.
Check "gem" command tightly now.
Basic
Help
$ gem -h
Display version
$ gem -v
2.5.1
Update gem itself.
$ gem update --system ... Display change log. ... $ gem -v 2.6.2
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 *** REMOTE GEMS *** rspec (3.4.0)
Search file on local
Check install directory for the gem.
$ gem contents rspec --show-install-dir $HOME/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rspec-3.4.0
Search file path for the specified file.
$ gem which rspec $HOME/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rspec-3.4.0/lib/rspec.rb $ gem which rails $HOME/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails.rb
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 rspec-3.4.0.gem $ gem unpack rspec-3.4.0.gem Unpacked gem: '... rspec-3.4.0' $ ls rspec-3.4.0/ rspec-3.4.0.gem
Case: update one gem to latest version.
$ gem list rubocop *** LOCAL GEMS *** rubocop (0.36.0)
$ gem list "^rubocop$" --remote *** REMOTE GEMS *** 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 or $ 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)