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 installations.
RubyGems is designed to easily manage gem installed tools, as well as servers for distribution gems. This is similar to apt-get under Ubuntu, yum of Centos, pip of Python.
RubyGems was founded around November 2003 and has been part of the Ruby Standard Library since Ruby 1.9.
If your Ruby is below version 1.9, you can also install it manually:
- Download the installation package first: https://rubygems.org/pages/download.
- Unzip and enter the directory and execute the command: ruby setup.rb
Update the RubyGems command:
$ gem update --system # 需要管理员或root用户
Gem
Gems are package managers for Ruby modules called Gems. It contains package information, as well as the files used to install it.
Gems are usually built from ".gemspec" files and contain YAML files about Gem information. Ruby code can also establish Gem directly, which is usually the case with Rake.
Gem command
Gem commands are used to build, upload, download, and install Gem packages.
Gem usage
RubyGems is functionally very similar to apt-get, portage, yum, and npm.
Installation:
gem install mygem
Unloading:
gem uninstall mygem
List installed gems:
gem list --local
List available gems, such as:
gem list --remote
Create ANDoc documents for all gems:
gem rdoc --all
Download a gem, but do not install:
gem fetch mygem
Search from available gems, such as:
gem search STRING --remote
The build of the gem package
Gem commands are also used to build and maintain .gemspec and .gem files.
Build.gemspec files with .gemspec files:
gem build mygem.gemspec
Modify the domestic source
For domestic network reasons (you know), the rubygems.org files stored on Amazon S3 failed intermittently.
So you don't respond for half a day when you encounter a gem install rack or bundle install, and you can view the execution with gem install rails -V.
So we can modify it to Taobao Download Source: http://ruby.taobao.org/
First, look at the current source:
$ gem sources -l *** CURRENT SOURCES *** https://rubygems.org/
Next, remove https://rubygems.org/ and add the Taobao download http://ruby.taobao.org/.
$ gem sources --remove https://rubygems.org/ $ gem sources -a https://ruby.taobao.org/ $ gem sources -l *** CURRENT SOURCES *** https://ruby.taobao.org # 请确保只有 ruby.taobao.org $ gem install rails
If you use Gemfile and Bundle (ex: Rails project)
You can mirror the command with bundle's gem source code.
$ bundle config mirror.https://rubygems.org https://ruby.taobao.org
So you don't have to change your Gemfile source.
source 'https://rubygems.org/' gem 'rails', '4.1.0' ...