All notes
Gem

Gem

Quick Start

rubygems guides.


# Check source.
gem sources

# Rebuild index for affected sources, e.g.
gem generate_index http://gems.rubyforge.org

# -d: detail
gem search ^rails [-d]

gem install GEMNAME --source http://rubygems.org

gem list

# Read doc for installed GEMNAME:
ri $GEMNAME
# Read doc on http server:
gem server

# Fetch and read without installation. If you doubt about security of GEMNAME:
gem fetch $GEMNAME
gem unpack $GEMNAME

gem build GEMNAME.gemspec
gem install gemname-version.gem

# Specify that a gem should come from a git repository with a .gemspec at its root
# Because Rubygems lacks the ability to handle gems from git, any gems installed from a git repository will not show up in gem list.
# They will, however, be available after running Bundler.setup.
gem 'nokogiri', :git => 'https://github.com/tenderlove/nokogiri.git'

# What if
# /usr/bin/ruby extconf.rb 
# mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h
sudo yum -y install ruby-devel

# See environment.
gem env
# Notice the two sections for:
  # INSTALLATION DIRECTORY
  # GEM PATHS

# gem sources should at least contain https://rubygems.org. If not
gem sources -a https://rubygems.org

SO provides a brief introduction to: gems, RubyGems, bundler, rvm, gemsets.

Ref.

Can't install passenger

Ref. Put passenger gem to Gemfile.

FAQ

Newer gem installed but old ones are required


gem uninstall then install the old version again

Establish googleapis mirror


git clone https://github.com/rmm5t/googleapis-mirror.git
cd googleapis-mirror
sudo yum install rubygem-rake
gem install bundler
gem install io-console
bundle install

rake sync
# The following step could be replaced by Apache/Nginx.
# sudo rake serve

Then let Apache server these files as a mirror:


<VirtualHost *:80>
  ServerName ajax.googleapis.com
  DocumentRoot "/path/to/googleapis-mirror"
  <Directory "/path/to/googleapis-mirror">
    Options Indexes
    Require all granted
  </Directory>
</VirtualHost>

Then add in your hosts:

yourMirrorIP ajax.googleapis.com

Mirrors for ruby gems

ruby-china.org.


# If there is SSL certificate problem, change https to http:
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
gem sources -l

gem update --system
gem -v