Ruby RubyGems

RubyGems is a package manager for Ruby that provides a standard format for distributing Ruby programs and libraries, as well as a tool for managing package installation.

RubyGems is designed to easily manage the tools installed by the gem and the servers used to distribute the gem. This is similar to apt-get under Ubuntu, yum for Centos, and pip for Python.

RubyGems was created in November 2003 and became part of the Ruby standard library from Ruby 1.9.

If your Ruby is lower than version 1.9, you can also install it manually:

Update the RubyGems command:

$ gem update -- System # requires administrator or root user


Gem is a package manager for Ruby modules (called Gems). It contains package information and files for installation.

Gem is usually built from a ".gemspec" file and contains YAML files about Gem information. Ruby code can also build Gem directly, in which case Rake is usually used.

gem command


gem command is used to build, upload, download, and install Gem packages.

gem usage

RubyGems is very similar in function to apt-get, portage, yum, and npm.


gem install mygem


gem uninstall mygem

List installed gems:

gem list --local 

List available gems, for example:

gem list --remote 

Create RDoc documentation for all gems:

gem rdoc --all 

Download a gem but don't install it:

gem fetch mygem

Search from available gems, for example:

gem search STRING -- Remote

Building of gem package


gem command is also used to build and maintain .gemspec and .gem files.

Build .gem with a .gemspec file:

gem build mygem.gemspec 

Modify domestic source

Due to domestic network reasons (you know), the intermittent connection of resource files on rubygems.org stored on Amazon S3 failed.

So you will not respond when you encounter gem install rack or bundle install for a long time. You can use gem install rails -V to view the execution process.

So we can change it to a domestic download source: https://gems.ruby-india.com

First, check the current source:

$ gem sources -l


Next, remove https://rubygems.org/ and add the domestic download source https://gems.ruby-india.com/.

$ gem sources -- Remove https://rubygems.org/
$ gem sources -a https://gems.ruby-india.com/
$ gem sources -l

# Make sure that only gems.ruby-india.com
$ gem install rails

If you use Gemfile and Bundle (for example: Rails project)

You can use the bundle's gem source code to mirror commands.

$ bundle config mirror. Https://rubygems.org https://gems.ruby-india.com/

This way you don't have to change the source of your Gemfile.

source 'https://rubygems.org/'
Gem 'rails', '4.1.0'

welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.