Ruby
Ruby is an essential build tool for developing. Many utilities or their installation scripts are built with Ruby language, or the Ruby package manager, RubyGems. For the convenience for versions switching, and with the reason not messing up the native Ruby installed by OS X, we employee rbenv to manage the Ruby versions. An alternative is RVM and rbenv is incompatible with RVM. There is a comic showing you a comparison. 
Installing Ruby with rbenv
rbenvworks by inserting a directory of shims at the front of your PATH through a process called rehashing.rbenvmaintains shims in that directory to match every Ruby command across every installed version of Ruby—irb,gem,rake,rails,ruby, and so on.
Installing rbenv
Install the
rbenvsuite which includesrbenv—The main utility,ruby-build—provides therbenv install/uninstall/buildcommand,rbenv-default-gems—hooks intorbenv installcommand to automatically install gems every time you install a new version of Ruby.brew install rbenv ruby-build rbenv-default-gemsAdd
rbenvplugin intooh-my-zsh. It initilizerbenvautomatically when you are logining shell and changes the defualtrbenvvariables.Check Zsh plugins: rbenv section:
Plugin
rbenvchanges the defualtrbenvvariables and exports them, provides some useful related function, explicitly tellsrbenvto use Zsh, and initilize therbenvautomatically.With the reason you install
rbenvby Homebrew, this plugin will point therbenvdirectory under Homebrew formulea repository, instead of~/.rbenv, to RBENV_ROOT.Reopen a new terminal tab or restart your shell for sourcing settings.
Install Ruby
Get the versions of Ruby:
rbenv install --listInstall the Ruby version:
rbenv install <version>Rehash for shims work:
rbenv rehashSet the Ruby version to replace the system built-in version:
rbenv global <version>Check the installed ruby versions or the current working version
rbenv versions rbenv version
Specifing the Ruby running version for shims
When you execute a shim, rbenv specifies the running version of Ruby for this shim by reading a specified env variable or some files in order:
RBENV_VERSIONenvironment variable.- The first 
.ruby-versionfile in the directory of the target script or in the script's parent directories. - The first 
.ruby-versionfile in the current working directory or the parent directories. - The global 
.rub-versionfile located in the directory is pointed by RBENV_ROOT variable. 
Note:
rbenv local <version>changes the content of.ruby-versionfile under current working directory.rbenv global <version>changes the content of.ruby-versionfile under RBENV_ROOT.--unsetoption cancel the version specifying.
Binding gems with each new Ruby version
rbenv-default-gemsautomatically installs the gems listed in$(rbenv root)/default-gemsfile every time you successfully install a new version of Ruby with rbenv install.
A Sample file:
# One per line
bundler
rbenv-gem-rehash
# Specifing a version
bcat ~>0.6
# Specifing prerelease version
rails --pre
RubyGems
RubyGems is a package management framework for Ruby. This gem is an update for the RubyGems software. You must have an installation of RubyGems before this update can be applied.
RubyGems is bounded to Ruby by default, to upgrade to the latest RubyGems, run:
gem update --system
Usages
# List installed or remote gems with/without details:
gem list [-r] [-d] [REGEXP]
# Install a gem with/without document:
gem install <gem> --no-document
# Show outdated gems
gem outdated
# Update installed gems or a particular gem:
gem update [<gem>]
# Clean up old versions of installed gems
gem cleanup [--dryrun]
# Show the dependencies of an installed gem, or reverse dependencies
gem dependency [-R]
Note: For a faster gem installation, add option --no-document disable documentation generation. Add a config into ~/.gemrc make it be default for each installation command:
echo 'gem: --no-document' >> ~/.gemrc
Tab-completion
Check Zsh plugins: gem section:
Plugin gem for Zsh enables the tab-completion feature.