By Wael

Posted :

What is ruby , rbenv , RubyGems , gem , bundler , and cocoapods

This tutorial , will show what is ruby , rbenv , RubyGems , gem , bundler , and cocoapods . It will also show , how to install rbenv , the commands that can be used with rbenv , how to use the gem command , and how to install cocoapods .

What is ruby , rbenv , RubyGems , gem , bundler , and cocoapods
Table of contents What is ruby and rbenv ? How to install rbenv ? rbenv cheat sheet List the available versions , that can be installed Install a ruby version Rehash available commands Check , what are the installed , ruby versions Check , the ruby version , currently in use Set and get , the default global ruby version , to be used Set , get , and unset , the local ruby version , to be used Set , get , and unset , the ruby shell version , to be used For a command , displays the ruby versions , that have it What is Rubygems , gem and bundler ? gem cheat sheet Display information about the ruby environment Searching for gems Installing gems Updating Uninstalling gems Add or remove sources , to download and install , gems Getting help What is CocoaPods ?

1- What is ruby and rbenv ?

Ruby is a programming language , used generally for web development , through a ruby library called rails .

Under macOS , ruby comes pre-installed , and it can be found under : /System/Library/Frameworks/Ruby.framework/Versions/ . Starting macOS Catalina version 10.15 , this is deprecated , and future versions of macOS might not contain ruby by default .

Rbenv is a ruby version manager , which allows to select the ruby version to be active . It also allows to install multiple versions of ruby .

Rbenv installs under the current user directory : ~/.rbenv , and the installed ruby versions , are installed , under : ~/.rbenv/versions

2- How to install rbenv ?

To install rbenv , both xcode and xcode command line tools , must be installed . They can be downloaded , from the apple developer webpage .

Once downloaded , what must be done , to install rbenv , is :

# First clone rbenv , using the following command :
git clone https://github.com/rbenv/rbenv.git ~/.rbenv


# Then execute :
cd ~/.rbenv && src/configure && make -C src
 
 
# if macOS before catalina , and using bash , execute : 
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
 
 
# if macOS catalina and after , and using zsh , execute : 
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
 

# Next execute : 
~/.rbenv/bin/rbenv init
 

# Next execute : 
nano ~/.bash_profile 
# and to autoload rbenv , add :
eval "$(rbenv init -)"
# ctrl-x , to save and exit 
 
 
# execute
source ~/.bash_profile
# if the default shell is bash .
# Usually , this is true for macOS 
# versions , prior to catalina .

# or execute : 
source ~/.zshrc
# if the default shell is zsh .
# Usually this is true , for 
# macos catalina , and after .
 
 
# install ruby build , to install ,
# versions of ruby 
mkdir -p "$(rbenv root)"/plugins

git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
 
 
# verify rbenv has been installed correctly
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash

3- rbenv cheat sheet

3.1- List the available versions , that can be installed

rbenv install -l
# List the available versions that can
# be installed 

# For example :
@difyel:~$ rbenv install -l
1.8.5-p52
1.8.5-p113
1.8.5-p114
1.8.5-p115
1.8.5-p231
1.8.6
...

3.2- Install a ruby version

rbenv install <version_number>
# Install a version , with the given number

# For example :
@difyel:~$ rbenv install 2.7.1
# installs the stable version 2.7.1

3.3- Rehash available commands

After installing , or removing , a ruby version , rbenv must be updated , with the available commands , from ruby versions .

rbenv rehash
# Is used to update rbenv , with the 
# available commands , from ruby versions .

# For example :
@difyel:~$ rbenv rehash
# rehashes the available commands

3.4- Check , what are the installed , ruby versions

rbenv versions
# Is used to check , what are the installed versions

For example :

@difyel:~$ rbenv versions
* system
2.7.1

Two versions are installed . The ruby version used by rbenv is marked by an * . In this case it is system . system is the version which is found on the system , as if rbenv does not exist . For macOs catalina and prior , it is located under : /System/Library/Frameworks/Ruby.framework/Versions/

3.5- Check , the ruby version , currently in use

rbenv version
# Displays the ruby version currently 
# in use .

For example :

@difyel:~$ rbenv version
system

system is the version currently in use . system is the version which is found on the system , as if rbenv does not exist . For macOs catalina and prior , it is located under : /System/Library/Frameworks/Ruby.framework/Versions/

3.6- Set and get , the default global ruby version , to be used

rbenv global <version_number>
# Sets the default global ruby version
# to be used .

For example :

@difyel:~$ rbenv global 2.7.1
# Sets the ruby version to be used globally ,
# to 2.7.1 

@difyel:~$ rbenv versions
# Displays the installed versions 
system
* 2.7.1 (set by /Users/difyel/.rbenv/version)
# The version in use now is 2.7.1
# This has been set by using rbenv global .
# rbenv global saves the global version 
# number , in ~/.rbenv/version .
	

To display the global version in use :

rbenv global
# Displays the global version in use

For example :

@difyel:~$ rbenv global 
2.7.1
# The global version in use , is 
# 2.7.1

3.7- Set , get , and unset , the local ruby version , to be used

rbenv local <version_number>

Is used , to set a ruby default version , locally , for a project . A local version overrides the global version . rbenv local , writes the local version number , to a file , named : .ruby-version , placed in the current working directory . rbenv will search for a .ruby-version file , in the current directory , and the parent directory , till it reaches the / root directory . For example :

@difyel:~$ rbenv global 
2.7.1
# Set the global version to 2.7.1

@difyel:~$ mkdir rbproject && cd rbproject 
# Create a directory called rbproject , and 
# cd into the directory . 

@difyel:~/rbproject$ rbenv local system
# Set the default version of ruby , 
# for the project , to system .

@difyel:~/rbproject$ rbenv version
# Display the ruby version in use .
system (set by /Users/difyel/rbproject/.ruby-version)
# The ruby version in use is system .
# It is set inside rbproject , by using 
# the .ruby-version file .

@difyel:~/rbproject$  mkdir subdirectory && cd subdirectory
# Create a directory named subdirectory 
# inside rbproject , and cd into it .

@difyel:~/rbproject/subdirectory$ rbenv version
# Display the ruby version in use  , from within
# this directory .
system (set by /Users/difyel/rbproject/.ruby-version)
# The version used is the local version . The local 
# version number is found inside the .ruby-version file , 
# found inside the rbproject folder , which is  the parent 
# folder , of the directory named subdirectory.

To unset , the local ruby version used , and from within the directory , where the .ruby-version file exists , issue :

rbenv local --unset
# Unsets the local ruby version used .
# This must be issued inside the directory , 
# where the .ruby-version file exists .

For example , and continuing with the previous example

@difyel:~/rbproject/subdirectory$ rbenv local --unset
# Unsets the local version inside   
# subdirectory

@difyel:~/rbproject/subdirectory$ rbenv version
# Displays the ruby version in use 
system (set by /Users/difyel/rbproject/.ruby-version)
# The version in use is still the version set
# inside the rbproject folder , which is the parent 
# of the directory , named subdirectory . 

@difyel:~/rbproject/subdirectory$ cd ..
# cd into subdirectory , parent directory :
# rbproject 

@difyel:~/rbproject$ rbenv local --unset
# Unset the local version in rbproject .

@difyel:~/rbproject$ rbenv version
# Display the version currently in use 
2.7.1 (set by /Users/difyel/.rbenv/version)
# The version in use now , is the global 
# version , set inside : ~/.rbenv/version

To display the local version in use , issue :

rbenv local
# Displays the local version in use .

For example , and continuing with the previous example :

@difyel:~/rbproject$ rbenv local
# Displays the local version in use ,
# inside a directory , or one of its parents .
rbenv: no local version configured for this directory	
# No local version was set inside the rbproject 
# directory , or in one of its parents . 

3.8- Set , get , and unset , the ruby shell version , to be used

rbenv shell <version_number>

Sets the shell version . The shell version overrides both the local and global version . For example :

@difyel:~$ rbenv shell 2.7.1
# Sets the ruby version to be used to 
# 2.7.1 

@difyel:~$ rbenv version
# Display the version in use 
2.7.1 (set by RBENV_VERSION environment variable)
# The version in use is 2.7.1 
# set by using rbenv shell , which writes 
# the version number , to a shell environment 
# variable , named RBENV_VERSION

To unset , the ruby version number , set by using the shell environment variable :

rbenv shell --unset 
# Unsets the ruby version number , set ,
# by using the shell environment variable .

For example , and continuing the previous example :

@difyel:~$ rbenv shell --unset
# Unsets the ruby version , set by using 
# rbenv shell 
@difyel:~$ rbenv version
2.7.1 (set by /Users/difyel/.rbenv/version)
# The ruby version in use now , is the one 
# set by using rbenv global , which writes 
# the version number to be used inside 
# ~/.rbenv/version

To display the ruby version number set by using rbenv shell , use:

rbenv shell 
# Display the ruby version , set , by using 
# rbenv shell 

For example , and continuing the previous example :

@difyel:~$ rbenv shell
# Displays the ruby version set 
# using the shell environment variable . 
rbenv: no shell-specific version configured 
# no shell version has been set using 
# rbenv shell 

3.9- For a command , display the ruby versions , that have it

rbenv whence <name_of_command>
# Display for a command , the installed 
# ruby versions that have it installed .

For example :

@difyel:~$ rbenv whence gem
2.7.1
# Only one ruby version is installed . 
# Version 2.7.1 have the gem command 
# installed . rbenv whence , does not 
# display for the system version , if it 
# has a command installed . 

4- What is Rubygems , gem and bundler ?

Rubygems is ruby package manager . A package in ruby is called a gem . Rubygems comes with ruby , since version 1.9 .

Bundler is itself a gem , and is a gem or package manager , for a given ruby application .

A gem contains a .gemspec file , which details information about a gem , such as : its name , its dependencies , its version number ... Gems are installed by using the gem command .

A Gemfile is used by bundler , to detail for an application , its gems .

5- gem cheat sheet

5.1- Display information about the ruby environment

To display information , about the ruby environment , use :

gem env

For example :

@difyel:~$  gem env
# Displays information about the 
# ruby environment . 

RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.14.1
    # The installed version of RUBYGEMS
  - RUBY VERSION: 2.0.0 (2015-12-16 patchlevel 648) [universal.x86_64-darwin16]
    # The installed version of RUBY
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0
    # Where Gems will be installed 
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
	# Where the RUBY executable is found
	# /System/Library/Frameworks/Ruby.framework/Versions/
	# is where Ruby is pre installed , for macOS  
	# catalina , and before . 
  - EXECUTABLE DIRECTORY: /usr/local/bin
    # Where the executable gems are found
  - RUBYGEMS PLATFORMS:
	- ruby
	- universal-darwin-16
	# The supported Gems platform 
	    # CPU : universal 
	    # OS : darwin 
	    # version : 16
  - GEM PATHS:
	- /Library/Ruby/Gems/2.0.0
	- /Users/difyel/.gem/ruby/2.0.0
	- /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
	# The Directories where ruby look up for Gems .
	# Library/Ruby/Gems/2.0.0 is where gems 
	# are installed .
	# /Users/difyel/.gem/ruby/2.0.0 is where gems 
	# are installed when using --user-install
	# /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0 is
	# where System pre installed gems are .
  - GEM CONFIGURATION:
	- :update_sources => true
	   # Updates for the repository meta data are enabled
	- :verbose => true
	   # Sets the gem command , to provide details , about what 
	   # it is doing . 
	- :backtrace => false
	   # Do not print a backtrace , when RubyGems
	   # encounters an error .
	- :bulk_threshold => 1000
	   # Download in bulk when the threshold
	   # of missing gems , is greater than 1000
   - REMOTE SOURCES:
	   - https://rubygems.org/
	   # The sources from which gems are download ,
	   # and installed  .

if using rbenv , for example :

@difyel:~$  rbenv global 2.7.1
# Set the global ruby version to 2.7.1
# using rbenv 

@difyel:~$  gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 3.1.2
  - RUBY VERSION: 2.7.1 (2020-03-31 patchlevel 83) [x86_64-darwin16]
  - INSTALLATION DIRECTORY: /Users/difyel/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0
  - USER INSTALLATION DIRECTORY: /Users/difyel/.gem/ruby/2.7.0
  - RUBY EXECUTABLE: /Users/difyel/.rbenv/versions/2.7.1/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /Users/difyel/.rbenv/versions/2.7.1/bin
  - SPEC CACHE DIRECTORY: /Users/difyel/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/difyel/.rbenv/versions/2.7.1/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-16
  - GEM PATHS:
     - /Users/difyel/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0
     - /Users/difyel/.gem/ruby/2.7.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/difyel/.rbenv/versions/2.7.1/bin
     - /Users/difyel/.rbenv/libexec
     - /Users/difyel/.rbenv/plugins/ruby-build/bin
     - /Users/difyel/.rbenv/shims
     - /Users/difyel/.rbenv/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin

5.2- Searching for gems

To list the gems which are installed locally , use :

gem search --local
# Displays gem installed locally .

#For example : 
@difyel:~$ gem search  --local

*** LOCAL GEMS ***

benchmark (default: 0.1.0)
bigdecimal (default: 2.0.0)
bundle (0.0.1)
bundler (default: 2.1.4)
...

To search for a remotely available gem , using regex , use :

gem search <regex>
# Search using a regular expression ,
# for a remotely available gem 

# For example  : 
@difyel:~$ gem search '^bundler.*h$'
# Search for a gem , which starts with 
# bundler , followed by any number 
# of characters , and which ends with 
# the letter h

*** REMOTE GEMS ***

bundler-dependency_graph (0.1.0)
bundler-patch (1.2.0)
bundler-squash (0.1.0)

To display detailed information about a gem , use :

gem search <regex> -d
# Displays detailed information about a gem , 
# matched by the regex 

# For example : 
@difyel:~$ gem search '^bundler$' -d 
# Display information about 
# gems , which starts and ends , with 
# the word bundler 
bundler (2.1.4)
Authors: André Arko, Samuel Giddins, Colby Swandale, Hiroshi
Shibata, David Rodríguez, Grey Baker, Stephanie Morillo, Chris
Morris, James Wen, Tim Moore, André Medeiros, Jessica Lynn Suttles,
Terence Lee, Carl Lerche, Yehuda Katz
Homepage: https://bundler.io

The best way to manage your application s dependencies

To display all versions , of gems , which are matched by a regular expression , use :

gem search <regex> -a
# Displays all versions , of gems ,
# which are matched by the regular 
# expression . 

# For example : 
gem search -d '^bundler$' -a
# Search for a gem which starts 
# and ends with bundler . Display
# detailed information , and all the 
# available versions . 

*** REMOTE GEMS ***

bundler (2.1.4, 2.1.3, 2.1.2, 2.1.1, 2.1.0, 2.0.2, 2.0.1, 2.0.0, 1.17.3, 1.17.2, 1.17.1, 1.17.0, 1.16.6, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16.0, 1.15.4, 1.15.3, 1.15.2, 1.15.1, 1.15.0, 1.14.6, 1.14.5, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14.0, 1.13.7, 1.13.6, 1.13.5, 1.13.4, 1.13.3, 1.13.2, 1.13.1, 1.13.0, 1.12.6, 1.12.5, 1.12.4, 1.12.3, 1.12.2, 1.12.1, 1.12.0, 1.11.2, 1.11.1, 1.11.0, 1.10.6, 1.10.5, 1.10.4, 1.10.3, 1.10.2, 1.10.1, 1.10.0, 1.9.10, 1.9.9, 1.9.8, 1.9.7, 1.9.6, 1.9.5, 1.9.4, 1.9.3, 1.9.2, 1.9.1, 1.9.0, 1.8.9, 1.8.8, 1.8.7, 1.8.6, 1.8.5, 1.8.4, 1.8.3, 1.8.2, 1.8.1, 1.8.0, 1.7.15, 1.7.14, 1.7.13, 1.7.12, 1.7.11, 1.7.10, 1.7.9, 1.7.8, 1.7.7, 1.7.6, 1.7.5, 1.7.4, 1.7.3, 1.7.2, 1.7.1, 1.7.0, 1.6.9, 1.6.8, 1.6.7, 1.6.6, 1.6.5, 1.6.4, 1.6.3, 1.6.2, 1.6.1, 1.6.0, 1.5.3, 1.5.2, 1.5.1, 1.5.0, 1.3.6, 1.3.5, 1.3.4, 1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.5, 1.2.4, 1.2.3, 1.2.2, 1.2.1, 1.2.0, 1.1.5, 1.1.4, 1.1.3, 1.1.2, 1.1.1, 1.1.0, 1.0.22, 1.0.21, 1.0.20, 1.0.18, 1.0.17, 1.0.15, 1.0.14, 1.0.13, 1.0.12, 1.0.11, 1.0.10, 1.0.9, 1.0.7, 1.0.5, 1.0.3, 1.0.2, 1.0.0, 0.9.26, 0.9.25, 0.9.24, 0.9.23, 0.9.22, 0.9.21, 0.9.20, 0.9.19, 0.9.18, 0.9.17, 0.9.16, 0.9.15, 0.9.14, 0.9.13, 0.9.12, 0.9.11, 0.9.10, 0.9.9, 0.9.8, 0.9.7, 0.9.6, 0.9.5, 0.9.4, 0.9.3, 0.9.2, 0.9.1, 0.9.0, 0.8.1, 0.8.0, 0.7.2, 0.7.1, 0.7.0, 0.6.0, 0.5.0, 0.4.1, 0.4.0, 0.3.1, 0.3.0)
Authors: André Arko, Samuel Giddins, Colby Swandale, Hiroshi
Shibata, David Rodríguez, Grey Baker, Stephanie Morillo, Chris
Morris, James Wen, Tim Moore, André Medeiros, Jessica Lynn Suttles,
Terence Lee, Carl Lerche, Yehuda Katz
Homepage: https://bundler.io

To check if a gem is installed , use :

gem search <gem_name> -i
# Checks if a gem is installed 

# For example : 
@difyel:~$ gem search bundler -i
# Checks if the bunlder gem is installed 
true
# Result is true 

To view the dependencies of a gem , use :

gem dependency <regex>
# For a gem which is installed 
# on the system 

gem dependency <regex> --remote
# For a gem which is not installed 
# on the system 

# For example : 
@difyel:~$ gem dependency zenduty --remote
# List the dependencies of zenduty .
# zenduty is not installed locally ,
# on the system . This is why --remote 
# was used . 
Gem zenduty-1.0.0
  bundler (>= 0, development)
  httparty (>= 0, development)
  rake (~> 10.0, development)

5.3- Installing gems

To install a gem , use :

gem install <gem_name>

# For example :
@difyel:~$ rbenv global system 
# rbenv is a ruby version manager  , 
# If not installed the default ruby 
# version is the one installed with the 
# system . If installed , rbenv global system , 
# sets the default ruby version to the 
# system version 

@difyel:~$ gem install bundler
Fetching: bundler-2.1.4.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
	You don t have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
# The default installion directory for system ruby ,
# is : /Library/Ruby/Gems/2.0.0 
# To install to : /Library/Ruby/Gems/2.0.0 
# sudo must be used . 

@difyel:~$ sudo gem install bundler
ERROR:  Error installing bundler:
	bundler requires Ruby version >= 2.3.0.
# gem install , will install the latest version 
# of a package . The latest bundler version 
# requires a version of ruby >= 2.3.0.
# , as such there was a problem installing 
# bundler . 

To specify the version of a gem to install , use :

gem install <gem_name> -v 
# Specify the version of a gem to install 

# For example 
@difyel:~$ sudo gem install bundler -v 1.3
# Install version 1.3 of bundler , which is 
# compatible , with the system version of ruby :
# 2.0.0 
Fetching: bundler-1.3.0.gem (100%)
Successfully installed bundler-1.3.0
Parsing documentation for bundler-1.3.0
Installing ri documentation for bundler-1.3.0
1 gem installed

To install a gem in the user directory , use :

gem install <gem name> --user-install
# Instead of using sudo to install gems , 
# the gems will be installed in the user 
# directory /Users/difyel/.gem/ruby/2.0.0

# For example 
@difyel:~$ gem install gel --user-install
Fetching: gel-0.3.0.gem (100%)
WARNING:  You don t have /Users/difyel/.gem/ruby/2.0.0/bin in your PATH,
	  gem executables will not run.
Successfully installed gel-0.3.0
Parsing documentation for gel-0.3.0
Installing ri documentation for gel-0.3.0
1 gem installed
# The gel gem has been installed to 
#  /Users/difyel/.gem/ruby/2.0.0/bin .

The warning is stating that the directory /Users/difyel/.gem/ruby/2.0.0/bin , containing executable gems , is not in the path , so the gel command will not be found .

The directory can be added to the path by :

# if running bash shell :
echo 'PATH=/Users/difyel/.gem/ruby/2.0.0/bin:$PATH' >> ~/.bash_profile

# if running zsh 
echo 'PATH=/Users/difyel/.gem/ruby/2.0.0/bin:$PATH' >> ~/.zshrc 

# Replace /Users/difyel/.gem/ruby/2.0.0/bin with the directory path 
# specified in the warning message . 

After adding the directory /Users/difyel/.gem/ruby/2.0.0/bin to the path , restart the shell .

Instead of using --user-install , to install gems for a local user , the GEM_HOME environment variable can be defined .

If defined , rubygems will by default install , the gems to the directory pointed by GEM_HOME . The directory pointed byGEM_HOME , will also be added to the paths , in which , ruby searches for gems . The GEM_HOME/bin directory , containing executable gems , must be added to the path , so that the executable gems , can be executed . For example :

# If running bash , define the GEM_HOME 
# environment variable , by issuing : 
echo 'export GEM_HOME=$HOME/.gem_home' >> ~/.bash_profile

# For zsh 
echo 'export GEM_HOME=$HOME/.gem_home' >>  ~/.zshrc

# Add the directory of the executable gems , in 
# the GEM_HOME directory , to PATH .

# if running bash 
echo 'PATH=$GEM_HOME/bin:$PATH' >> ~/.bash_profile

#if running zsh 
echo 'PATH=$GEM_HOME/bin:$PATH' >> ~/.zshrc

# After defining GEM_HOME , and the directory of the 
# executable gems , inside the GEM_HOME directory ,
# restart the shell .


@difyel:~$ gem environment gemdir
# Display The directory where gems will be installed 
/Users/difyel/.gem_home

@difyel:~$ gem environment gempath
# Display the path used to search 
# for gems 
# /Users/difyel/.gem/ruby/2.0.0:/Library/Ruby/Gems/2.0.0:/Users/difyel/.gem_home:/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
/Users/difyel/.gem/ruby/2.0.0
/Library/Ruby/Gems/2.0.0
/Users/difyel/.gem_home
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0

If a version beside system is set , using rbenv , what was described earlier , still apply .

What will change , is the location of the installation directory , for the gems installed , without using : --user-install , or without setting , the GEM_HOME environment variable .

By default , these gems will be installed , in : ~/.rbenv/versions/version_number/lib/ruby/ , where version_number can be for example 2.7.1 . As for the executable gems , they will be by default installed , in : /Users/difyel/.rbenv/versions/version_number/bin .

The location of the default installation directories , can be gotten , by using : rbenv environment .

Finally , to get information , about the path , where a gem is installed , use :

gem info <gem_name>

# For example  :
@difyel:~$ rbenv global 2.7.1 
# Set using rbenv the global 
# ruby version to 2.7.1 

@difyel:~$ gem info bigdecimal
# Display information about the 
# gem named bigdecimal 

*** LOCAL GEMS ***

bigdecimal (2.0.0)
    Authors: Kenta Murata, Zachary Scott, Shigeo Kobayashi
    Homepage: https://github.com/ruby/bigdecimal
    License: ruby
    Installed at (default): /Users/difyel/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0

	Arbitrary-precision decimal floating-point number library.
# The gem is installed at 
# /Users/difyel/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0

5.4- Updating

To update rubygems itself , use :

gem update -—system
# This , will update rubygems itself , 
# to the latest version

# For example : 
@difyel:~$  gem update --system
Updating rubygems-update
Fetching: rubygems-update-3.1.2.gem (100%)
ERROR:  Error installing rubygems-update:
	rubygems-update requires Ruby version >= 2.3.0.
ERROR:  While executing gem ... (NoMethodError)
	undefined method version for nil:NilClass
# In this case rubygems was not updated , since 
# rubygems version 3.1.2 , requires a version of 
# ruby >= 2.3.0

To update gems , use :

gem update 
# Will update all installed gems to the
# latest versions 

gem update <gem_name>
# To update a specific gem
# to the latest version 

To list the outdated gems , use :

gem outdated

# For example : 
@difyel:~$ gem outdated
# List the outdated gems 
bigdecimal (1.2.0 < 2.0.0)
io-console (0.4.2 < 0.5.6)
mini_portile2 (2.4.0 < 2.5.0)
minitest (4.3.2 < 5.14.0)
nokogiri (1.5.6 < 1.10.9)
psych (2.0.0 < 3.1.0)
rake (0.9.6 < 13.0.1)
rdoc (4.0.0 < 6.2.1)

5.5- Uninstalling gems

To uninstall a gem , use :

gem uninstall <gem_name>
# This will uninstall the gem  , 
# with the given name .
# If multiple versions , of the 
# gem is installed  , for example 
# by using --user-install , and by
# setting GEM_HOME  , 
# gem uninstall will display 
# a list to select from ,  which gem to 
# uninstall .

To uninstall , from GEM_HOME , old versions of gems which are not used , to satisfy any dependencies , use :

gem cleanup

To view what will be uninstalled , when using gem cleanup , without uninstalling anything , use :

gem cleanup --dryrun 

# For example : 
@difyel:~$ gem cleanup --dryrun
# Displays what : gem clean ,
# will uninstall , if ran wihtout 
# the --dryrun option .  
Cleaning up installed gems...
Dry Run Mode: Would uninstall sqlite3-1.3.7
Dry Run Mode: Would uninstall libxml-ruby-2.6.0
Dry Run Mode: Would uninstall CFPropertyList-2.2.8
Dry Run Mode: Would uninstall sqlite3-1.3.7
Dry Run Mode: Would uninstall libxml-ruby-2.6.0
Dry Run Mode: Would uninstall CFPropertyList-2.2.8
Clean Up Complete

To uninstall old gems , which are not used to satisfy any dependencies , installed by using the --user-install option , use :

gem cleanup --user-install

5.6- Add or remove sources , to download and install , gems

To add or remove sources , from which gems can be downloaded , use :

gem sources -a  <source_url>
# Adds a source url , to download gems from .

gem sources -r  <source_url>
# Removes a source url .

# For example : 
@difyel:~$ gem install bundler
# If a ruby version is using an old
# version of OpenSSL , this error 
# might happen 
ERROR:  Could not find a valid gem 'bundler' (>= 0), here is why:
		  Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: tlsv1 alert protocol version (https://rubygems.org/latest_specs.4.8.gz)
# The solution is  either to recompile the 
# old ruby version with a newer OpenSSL
# version  , or to remove the source 
# which uses ssl , and add a source 
# which does not . 

@difyel:~$ gem source -r https://rubygems.org/
# Remove the source which uses https

@difyel:~$ gem source -a http://rubygems.org/
# Add a source which does not use https 

To list all available sources , use :

gem sources --list

To clear all available sources cache , use :

gem sources -​-clear-all

5.7- Getting help

To get help , while using the gem command , use :

gem help

6- What is CocoaPods ?

CocoaPods , manages the dependencies , for a swift , or an objective c , project . It is used to add libraries for such projects .

A library in CocoaPods , is known as a : pod . A Podfile file , is used to state the dependencies , for an application .

To install CocoaPods , ruby version 2 , or greater , must exists .

gem install cocoapods --user-install

can be used to install CocoaPods for a given user .

If faced by the error :

ERROR:  Error installing activesupport:
minitest requires Ruby version ~> 2.2.

when using ruby version 2 , then install , before installing cocopoads , minitest version 5.11.3 , by using :

gem install minitest -v 5.11.3 --user-install

Also if faced with the error :

ERROR:  Could not find a valid gem 'cocoapods' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: tlsv1 alert protocol version (https://rubygems.org/latest_specs.4.8.gz)

then execute the following commands :

gem source -r https://rubygems.org/
# Remove the source which uses https
gem source -a http://rubygems.org/
# Add a source which does not use https

Finally , if faced with the warning :

WARNING:  You don't have /Users/difyel/.gem/ruby/2.0.0/bin in your PATH,
gem executables will not run.

Add the stated directory to your path , by :

# if running bash shell :
echo 'PATH=/Users/difyel/.gem/ruby/2.0.0/bin:$PATH' >> ~/.bash_profile
		 
# if running zsh 
echo 'PATH=/Users/difyel/.gem/ruby/2.0.0/bin:$PATH' >> ~/.zshrc

Substitute /Users/difyel/.gem/ruby/2.0.0/bin , by the directory path provided in the warning message , and restart the shell .