Ruby RubyGems
RubyGems is a package manager for Ruby, providing a standard format for distributing Ruby programs and libraries, as well as a tool for managing package installations.
RubyGems is designed to easily manage gem installations and servers for distributing gems. This is similar to apt-get on Ubuntu, yum on CentOS, and pip for Python.
RubyGems was created around November 2003 and has been part of the Ruby standard library since Ruby 1.9.
If your Ruby version is below 1.9, you can also install it manually:
First, download the installation package: https://rubygems.org/pages/download.
Unzip and enter the directory, then execute the command: ruby setup.rb
Update RubyGems command:
$ gem update --system # Requires administrator or root user
Gem
Gem is a package manager for Ruby modules (called Gems). It includes package information and files for installation.
Gems are usually built according to a ".gemspec" file, which contains a YAML file with Gem information. Ruby code can also directly create a Gem, in which case Rake is typically used.
gem Command
The gem command is used to build, upload, download, and install Gem packages.
gem Usage
RubyGems is similar in functionality to apt-get, portage, yum, and npm.
Install:
gem install mygem
Uninstall:
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 without installing it:
gem fetch mygem
Search from available gems, for example:
gem search STRING --remote
Building Gem Packages
The gem command is also used to build and maintain .gemspec and .gem files.
Build a .gem from a .gemspec file:
gem build mygem.gemspec
Modifying Domestic Sources
Due to domestic network issues (you know), resources hosted on Amazon S3 by rubygems.org intermittently fail to connect.
As a result, you may experience slow responses when running commands like gem install rack
or bundle install
. You can view the execution process with gem install rails -V
.
First, check the current sources:
$ gem sources -l
*** CURRENT SOURCES ***
https://rubygems.org/
Next, remove https://rubygems.org/
and add the domestic download source https://gems.ruby-china.com/
.
$ gem sources --remove https://rubygems.org/
$ gem sources -a https://gems.ruby-china.com/
$ gem sources -l
*** CURRENT SOURCES ***
https://gems.ruby-china.com/
# Ensure only gems.ruby-china.com is listed
$ gem install rails
If you use Gemfile and Bundle (e.g., Rails projects)
You can use the bundle gem source mirroring command.
$ bundle config mirror.https://rubygems.org https://gems.ruby-china.com/
This way, you don't need to change the source in your Gemfile.
source 'https://rubygems.org/'
gem 'rails', '4.1.0'
...