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 Tools designed to easily manage gem installations, as well as servers for distributing gems. This is similar to apt-get under Ubuntu, yum in Centos, and pip in Python.
RubyGems was created around November 2003 and has been part of the Ruby standard library since Ruby version 1.9.
If your Ruby version is lower than 1.9, you can also install it manually:
First download the installation package: https://rubygems.org/pages/download.
Unzip and enter the directory, execute the command: ruby setup.rb
Update RubyGems command:
$ gem update --system # 需要管理员或root用户
Gem
Gem is a package manager for Ruby modules (called Gems). It contains package information, as well as files used for installation.
Gem is usually built according to the ".gemspec" file, which contains a YAML file about Gem information. Ruby code can also create gems 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 are functionally very similar to apt-get, portage, yum and npm.
Installation:
gem install mygem
Uninstallation:
gem uninstall mygem
List installed gems:
gem list --local
List available gems, for example:
gem list --remote
Create RDoc documents for all gems:
gem rdoc --all
Download a gem, but not install it:
gem fetch mygem
Search from available gems, for example:
gem search STRING --remote
gem package construction
gem command is also used to build and maintain .gemspec and .gem files.
Use .gemspec file to build .gem:
gem build mygem.gemspec
Modify domestic source
Due to domestic network reasons (you know), rubygems.org is stored in Amazon Resource files on S3 intermittently fail to connect.
So you will encounter gem install rack or bundle install without response for half a day. Specifically, you can use gem install rails -V to view the execution process.
So we can modify it to Taobao download source: http://ruby.taobao.org/First, check the current source:
$ gem sources -l *** CURRENT SOURCES *** https://rubygems.org/
Then , remove https://rubygems.org/, and add Taobao download source 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 (for example: Rails project)
You can use the gem source code mirroring command of the bundle.
$ bundle config mirror.https://rubygems.org https://ruby.taobao.org
This way you don’t need to change the source of your Gemfile.
source 'https://rubygems.org/' gem 'rails', '4.1.0' ...