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:
- First download the installation package: https://rubygems.org/pages/download.
- Unzip and go to the directory and execute the command: ruby setup.rb
Update the RubyGems command:
$ gem update -- System # requires administrator or root user
Gem
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
Thegem 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.
Installation:
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 but don't install it:
gem fetch mygem
Search from available gems, for example:
gem search STRING -- Remote
Building of gem package
Thegem 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 modify it to Taobao download source: http://ruby.taobao.org/First, check the current source:
$ gem sources -l *** CURRENT SOURCES *** Https://rubygems.org/
Next, remove https://rubygems.org/ and add the 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 # Make sure that only ruby.taobao.org $ 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://ruby.taobao.org
This way you don't have to change the source of your Gemfile.
source 'https://rubygems.org/' Gem 'rails', '4.1.0' ...