Wilson Mar bio photo

Wilson Mar

Hello!

Calendar YouTube Github

LinkedIn

Switch among multiple versions of Ruby

US (English)   Norsk (Norwegian)   Español (Spanish)   Français (French)   Deutsch (German)   Italiano   Português   Estonian   اَلْعَرَبِيَّةُ (Egypt Arabic)   Napali   中文 (简体) Chinese (Simplified)   日本語 Japanese   한국어 Korean

Overview

ruby-stack-v01-300x213-11679.jpg The major commands around Ruby:

  1. ruby
  2. gem
  3. bundle
  4. rbenv version manager or
  5. rvm version manager

PROTIP: There is a war going on within the Ruby community between rvm and rbenv. See http://jonathan-jackson.net/rvm-and-rbenv and Ryan McGeary who switched to rbenv.

Versions

  1. Look at the list of Ruby versions at

    https://www.ruby-lang.org/en/downloads

  2. Remember the lastest version number (such as “2.7.1”).

    What Ruby version is installed?

    A Ruby language compiler is included in Mac OSX. So we can jump straight to view version information.

    CAUTION: Don’t touch the system Ruby that comes with your Mac.

  3. Open a Terminal Shell Window and type:

    ruby --version
    

    Alternately:

    ruby --version
    

    The response for the High Sierra default:

    ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin17] ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17] </tt>

    The response for the Sierra default:

    ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]

    The response for the Yosemite default:

    ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]

    The response after updating on 2016-06-16:

    ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]

    CAUTION: The Apple Mac operating system makes use of Ruby, so don’t delete the .rvm folder.

  4. This should return “hey”:

    ruby -e "puts 'hey'"
    

    PROTIP: The ruby command by itself will not return anything … forever.

    Gem version numbers

  5. You don’t really need to do the above because this more detailed command provides it as well:

    gem env
    

    The response on 2016-06-16:

    RubyGems Environment:
             - RUBYGEMS VERSION: 2.6.4
             - RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-darwin15]
             - INSTALLATION DIRECTORY: /Users/mac/.rvm/gems/ruby-2.3.1
             - USER INSTALLATION DIRECTORY: /Users/mac/.gem/ruby/2.3.0
             - RUBY EXECUTABLE: /Users/mac/.rvm/rubies/ruby-2.3.1/bin/ruby
             - EXECUTABLE DIRECTORY: /Users/mac/.rvm/gems/ruby-2.3.1/bin
             - SPEC CACHE DIRECTORY: /Users/mac/.gem/specs
             - SYSTEM CONFIGURATION DIRECTORY: /Users/mac/.rvm/rubies/ruby-2.3.1/etc
             - RUBYGEMS PLATFORMS:
     - ruby
     - x86_64-darwin-15
             - GEM PATHS:
      - /Users/mac/.rvm/gems/ruby-2.3.1
      - /Users/mac/.rvm/gems/ruby-2.3.1@global
             - GEM CONFIGURATION:
      - :update_sources => true
      - :verbose => true
      - :backtrace => false
      - :bulk_threshold => 1000
             - REMOTE SOURCES:
      - https://rubygems.org/
             - SHELL PATH:
      - /Users/mac/.rvm/gems/ruby-2.3.1/bin
      - /Users/mac/.rvm/gems/ruby-2.3.1@global/bin
      - /Users/mac/.rvm/rubies/ruby-2.3.1/bin
      - /Users/mac/depot_tools
      - /Users/mac/.npm-packages/bin
      - /Users/mac/miniconda2/bin
      - /Users/mac/.rbenv/shims
      - /Users/mac/.rbenv/bin
      - /usr/local/bin
      - /usr/bin
      - /bin
      - /usr/sbin
      - /sbin
      - /Users/mac/gits
      - /Users/mac/.rvm/bin
      - /Users/mac/.rvm/bin
    
  6. To view each component individually:

    gem --version
    

    The response for the High Sierra default:

    2.7.6

    The response for the Sierra default:

    2.0.14

    The response for the Yosemite default:

    2.0.14

    After updating on 2017-02-16:

    2.6.10

    QUESTION: List of versions?

    Update RubyGems and Bundler:

  7. Update:

    
    sudo gem update --system
    

    The response on 2016-06-16:

    Password:
    Updating rubygems-update
    Fetching: rubygems-update-2.6.4.gem (100%)
    Successfully installed rubygems-update-2.6.4
    Parsing documentation for rubygems-update-2.6.4
    Installing ri documentation for rubygems-update-2.6.4
    Installing darkfish documentation for rubygems-update-2.6.4
    Done installing documentation for rubygems-update after 2 seconds
    Parsing documentation for rubygems-update-2.6.4
    Done installing documentation for rubygems-update after 0 seconds
    Installing RubyGems 2.6.4
    RubyGems 2.6.4 installed
    Parsing documentation for rubygems-2.6.4
    Installing ri documentation for rubygems-2.6.4
     
    === 2.6.3 / 2016-04-05
    ...
    Minor enhancements:
    ...
    Bug fixes:
    ...
    RubyGems installed the following executables:
    /Users/mac/.rvm/rubies/ruby-2.3.1/bin/gem
     
    Ruby Interactive (ri) documentation was installed. ri is kind of like man 
    pages for ruby libraries. You may access it like this:
      ri Classname
      ri Classname.class_method
      ri Classname#instance_method
    If you do not wish to install this documentation in the future, use the
    --no-document flag, or set it as the default in your ~/.gemrc file. See
    'gem help env' for details.
     
    RubyGems system software updated
    
  8. List local gems:

    gem list b
    

    A sample example (on 2016-06-16):

    bigdecimal (1.3.1, 1.2.7, default: 1.2.0)
    libxml-ruby (3.0.0, 2.8.0, 2.6.0)
    rainbow (2.2.1, 2.1.0)
    rubocop (0.47.1, 0.40.0)
    bundler-unload (1.0.2)
    executable-hooks (1.3.2)
    rubygems-bundler (1.4.4)
    ruby-progressbar (1.8.1)
    rubygems-update (2.6.10, 2.6.9, 2.6.1)
    ...
    

    Update Bundler:

  9. If bundler is not on the list above:

    gem install bundler
    

    A sample response:

    Fetching: bundler-1.12.5.gem (100%)
    Successfully installed bundler-1.12.5
    Parsing documentation for bundler-1.12.5
    Installing ri documentation for bundler-1.12.5
    Done installing documentation for bundler after 5 seconds
    1 gem installed
    
  10. Navigate to a folder containing :

    bundle install
    

    A sample response:

    Fetching gem metadata from https://rubygems.org/
    Fetching version metadata from https://rubygems.org/
    Fetching dependency metadata from https://rubygems.org/
    Installing rake 11.1.2
    ...
    Bundle complete! 5 Gemfile dependencies, 39 gems now installed.
    Use `bundle show [gemname]` to see where a bundled gem is installed.
    
  11. Run

    sudo gem install --no-rdoc --no-ri bundler

    The response:

    Fetching: bundler-1.9.4.gem (100%)
    Successfully installed bundler-1.9.4
    1 gem installed
    
  12. Update latest version of gem:

    sudo gem update
    

    The response takes several minutes because it touches every gem:

       Updating installed gems
    Updating CFPropertyList
    ...
    RubyGems installed the following executables:
      /usr/local/Cellar/ruby/2.5.1/bin/gem
      /usr/local/Cellar/ruby/2.5.1/bin/bundle
     
    Ruby Interactive (ri) documentation was installed. ri is kind of like man 
    pages for Ruby libraries. You may access it like this:
      ri Classname
      ri Classname.class_method
      ri Classname#instance_method
    If you do not wish to install this documentation in the future, use the
    --no-document flag, or set it as the default in your ~/.gemrc file. See
    'gem help env' for details.
     
    RubyGems system software updated
    
  13. Press y and Enter if you see:

    rake's executable "rake" conflicts with /usr/bin/rake
    rdoc's executable "rdoc" conflicts with /usr/bin/rdoc
    rdoc's executable "ri" conflicts with /usr/bin/ri
    
  14. To rebuild any gems using native extensions:

    sudo gem pristine \-\-all 
    
  15. To uninstall gems not used:

    sudo gem cleanup
    

    The response:

    Cleaning up installed gems...
    Clean Up Complete
    

Install rbenv

CAUTION: To install rbenv, one must first remove RVM because it’s incompatible with rbenv.

brew update
   brew install rbenv ruby-build
   

The response:

==> Installing dependencies for rbenv: openssl, ruby-build
==> Installing rbenv dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2k.sierra.bottl
######################################################################## 100.0%
==> Pouring openssl-1.0.2k.sierra.bottle.tar.gz
==> Using the sandbox
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs
 
and run
  /usr/local/opt/openssl/bin/c_rehash
 
This formula is keg-only, which means it was not symlinked into /usr/local.
 
Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries
 
If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
 
For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include
For pkg-config to find this software you may need to set:
    PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
 
==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2k: 1,696 files, 12M
==> Installing rbenv dependency: ruby-build
==> Downloading https://github.com/rbenv/ruby-build/archive/v20170201.tar.gz
==> Downloading from https://codeload.github.com/rbenv/ruby-build/tar.gz/v201702
######################################################################## 100.0%
==> ./install.sh
🍺  /usr/local/Cellar/ruby-build/20170201: 334 files, 178.8K, built in 4 seconds
==> Installing rbenv 
==> Downloading https://homebrew.bintray.com/bottles/rbenv-1.1.0.sierra.bottle.t
######################################################################## 100.0%
==> Pouring rbenv-1.1.0.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/rbenv/1.1.0: 36 files, 63.2K
   
  1. What versions of Ruby are available? See https://www.ruby-lang.org/en/downloads/releases/

  2. To upgrade Ruby using rbenv, first get the semantic version from the Ruby site, then:

    rbenv install 2.6.1
    

    The response when 2.6.1 was all the rage:

    ruby-build: use openssl from homebrew
    Downloading ruby-2.6.1.tar.bz2...
    -> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.1.tar.bz2
    Installing ruby-2.6.1...
    ruby-build: use readline from homebrew
    Installed ruby-2.6.1 to /Users/wilsonmar/.rbenv/versions/2.6.1
    
  3. Make that version the default globally:

    rbenv global 2.6.1
    ruby -v
    

    The response I got:

    ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin18]

    Uninstall rbenv

  4. To uninstall, remember rbenv was installed using brew, so:

    brew uninstall rbenv ruby-build
    

Install to /usr/local/bin

“You don’t have write permissions into the /usr/bin directory.” is returned because that directory requires root credentials.

This is why Homebrew installs into the /usr/local/bin folder.

To specify that folder when installing gems, for example:

gem install cocoapods -n /usr/local/bin

PROTIP: To automatically specify -n /usr/local/bin, save create file ~/.gemrc containing:

:gemdir:
   - ~/.gem/ruby
install: -n /usr/local/bin
   

rbenv vs rvm

Before rbenv, there was rvm.

This article describes the differences.

PROTIP: Personally, the requirement for gpg to install was a turn-off for RVM as it was difficult to get working.

Ruby Version Manager (rvm)

See https://rvm.io/support/troubleshooting

Install RVM

  1. In a Terminal:

    curl -L https://get.rvm.io | bash -s stable

    Sample response:

      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed
    100   194  100   194    0     0    544      0 --:--:-- --:--:-- --:--:--   544
    100 24361  100 24361    0     0  31643      0 --:--:-- --:--:-- --:--:-- 1076k
    Downloading https://github.com/rvm/rvm/archive/1.29.4.tar.gz
    Downloading https://github.com/rvm/rvm/releases/download/1.29.4/1.29.4.tar.gz.asc
    gpg: Signature made Sun Jul  1 13:41:26 2018 MDT
    gpg:                using RSA key 62C9E5F4DA300D94AC36166BE206C29FBF04FF17
    gpg: Good signature from "Michal Papis (RVM signing) <mpapis@gmail.com>" [unknown]
    gpg:                 aka "Michal Papis <michal.papis@toptal.com>" [unknown]
    gpg:                 aka "[jpeg image of size 5015]" [unknown]
    gpg: WARNING: This key is not certified with a trusted signature!
    gpg:          There is no indication that the signature belongs to the owner.
    Primary key fingerprint: 409B 6B17 96C2 7546 2A17  0311 3804 BB82 D39D C0E3
      Subkey fingerprint: 62C9 E5F4 DA30 0D94 AC36  166B E206 C29F BF04 FF17
    GPG verified '/Users/wilsonmar/.rvm/archives/rvm-1.29.4.tgz'
    Upgrading the RVM installation in /Users/wilsonmar/.rvm/
     RVM PATH line found in /Users/wilsonmar/.mkshrc /Users/wilsonmar/.profile /Users/wilsonmar/.bashrc /Users/wilsonmar/.zshrc.
     RVM sourcing line found in /Users/wilsonmar/.profile /Users/wilsonmar/.bash_profile /Users/wilsonmar/.zlogin.
    Upgrade of RVM in /Users/wilsonmar/.rvm/ is complete.
    /Users/wilsonmar/.bash_profile:1:PATH=/usr/local/bin/python3:/usr/bin/python:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/share/dotnet
     
             * WARNING: Above files contains PATH= with no $PATH inside, this can break RVM,
     for details check https://github.com/rvm/rvm/issues/1351#issuecomment-10939525
     to avoid this warning prepend $PATH
     
             * No new notes to display.
    

    View rvm version number

    rvm info
    
  2. For a smaller response:

    rvm --version
    

    The response on 2018-10-26:

    rvm 1.29.4 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
    

    The response on 2016-06-16 had an email:

    rvm 1.27.0 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
    

Secure route:

See https://rvm.io/rvm/security

  1. First try:

    gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
    

    The response I got:

    gpg: keyserver receive failed: Server indicated a failure
    
  2. Alternatively, Since that doesn’t work:

    curl -sSL https://rvm.io/mpapis.asc | gpg --import -
    
    gpg: key 3804BB82D39DC0E3: 47 signatures not checked due to missing keys
    gpg: key 3804BB82D39DC0E3: public key "Michal Papis (RVM signing) <mpapis@gmail.com>" imported
    gpg: Total number processed: 1
    gpg:               imported: 1
    gpg: marginals needed: 3  completes needed: 1  trust model: pgp
    gpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
    
  3. Download:

    \curl -O https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed
    100 24361  100 24361    0     0  72332      0 --:--:-- --:--:-- --:--:-- 72502
    
  4. Download:

    \curl -O https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer.asc
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed
    100   833  100   833    0     0   3368      0 --:--:-- --:--:-- --:--:--  3372
    
  5. Verify:

     gpg --verify rvm-installer.asc
    gpg: assuming signed data in 'rvm-installer'
    gpg: Signature made Sat Mar 31 15:47:44 2018 MDT
    gpg:                using RSA key 62C9E5F4DA300D94AC36166BE206C29FBF04FF17
    gpg: Good signature from "Michal Papis (RVM signing) <mpapis@gmail.com>" [unknown]
    gpg:                 aka "Michal Papis <michal.papis@toptal.com>" [unknown]
    gpg:                 aka "[jpeg image of size 5015]" [unknown]
    gpg: WARNING: This key is not certified with a trusted signature!
    gpg:          There is no indication that the signature belongs to the owner.
    Primary key fingerprint: 409B 6B17 96C2 7546 2A17  0311 3804 BB82 D39D C0E3
      Subkey fingerprint: 62C9 E5F4 DA30 0D94 AC36  166B E206 C29F BF04 FF17
    
  6. Get on the latest version of RVM:

    bash rvm-installer stable

    The response run on 2018-06-22:

    Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
    Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc
    gpg: Signature made Sun Sep 10 14:59:21 2017 MDT
    gpg:                using RSA key E206C29FBF04FF17
    gpg: Good signature from "Michal Papis (RVM signing) <mpapis@gmail.com>" [unknown]
    gpg:                 aka "Michal Papis <michal.papis@toptal.com>" [unknown]
    gpg:                 aka "[jpeg image of size 5015]" [unknown]
    gpg: WARNING: This key is not certified with a trusted signature!
    gpg:          There is no indication that the signature belongs to the owner.
    Primary key fingerprint: 409B 6B17 96C2 7546 2A17  0311 3804 BB82 D39D C0E3
      Subkey fingerprint: 62C9 E5F4 DA30 0D94 AC36  166B E206 C29F BF04 FF17
    GPG verified '/Users/wilsonmar/.rvm/archives/rvm-1.29.3.tgz'
     
    Installing RVM to /Users/wilsonmar/.rvm/
     Adding rvm PATH line to /Users/wilsonmar/.profile /Users/wilsonmar/.mkshrc /Users/wilsonmar/.bashrc /Users/wilsonmar/.zshrc.
     Adding rvm loading line to /Users/wilsonmar/.profile /Users/wilsonmar/.bash_profile /Users/wilsonmar/.zlogin.
    Installation of RVM in /Users/wilsonmar/.rvm/ is almost complete:
     
             * To start using RVM you need to run `source /Users/wilsonmar/.rvm/scripts/rvm`
     in all your open shell windows, in rare cases you need to reopen all shell windows.
    /Users/wilsonmar/.bash_profile:1:PATH=/usr/bin/python:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/share/dotnet
     
             * WARNING: Above files contains `PATH=` with no `$PATH` inside, this can break RVM,
     for details check https://github.com/rvm/rvm/issues/1351#issuecomment-10939525
     to avoid this warning prepend `$PATH`.
    
  7. Do as instructed:

    source /Users/wilsonmar/.rvm/scripts/rvm

    No response is returned.

    Get latest version of Ruby

  8. Get on the latest version of RVM:

    rvm get stable

    The response run on 2017-07-27:

    ownloading https://get.rvm.io
    Downloading https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer.asc
    Verifying /Users/mac/.rvm/archives/rvm-installer.asc
    gpg: Signature made Sun Jul  2 16:42:38 2017 EDT using RSA key ID BF04FF17
    gpg: Good signature from "Michal Papis (RVM signing) <mpapis@gmail.com>" [unknown]
    gpg: Note: This key has expired!
    Primary key fingerprint: 409B 6B17 96C2 7546 2A17  0311 3804 BB82 D39D C0E3
      Subkey fingerprint: 62C9 E5F4 DA30 0D94 AC36  166B E206 C29F BF04 FF17
    GPG verified '/Users/mac/.rvm/archives/rvm-installer'
    Downloading https://github.com/rvm/rvm/archive/1.29.2.tar.gz
    Downloading https://github.com/rvm/rvm/releases/download/1.29.2/1.29.2.tar.gz.asc
    gpg: Signature made Thu Jun 22 12:18:38 2017 EDT using RSA key ID BF04FF17
    gpg: Good signature from "Michal Papis (RVM signing) <mpapis@gmail.com>" [unknown]
    gpg: Note: This key has expired!
    Primary key fingerprint: 409B 6B17 96C2 7546 2A17  0311 3804 BB82 D39D C0E3
      Subkey fingerprint: 62C9 E5F4 DA30 0D94 AC36  166B E206 C29F BF04 FF17
    GPG verified '/Users/mac/.rvm/archives/rvm-1.29.2.tgz'
     
    Upgrading the RVM installation in /Users/mac/.rvm/
     RVM PATH line found in /Users/mac/.mkshrc /Users/mac/.profile /Users/mac/.bashrc /Users/mac/.zshrc.
     RVM sourcing line found in /Users/mac/.profile /Users/mac/.bash_profile /Users/mac/.zlogin.
    Upgrade of RVM in /Users/mac/.rvm/ is complete.
     
    # Wilson Mar,
    #
    #   Thank you for using RVM!
    #   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
    #
    # ~Wayne, Michal & team.
     
    In case of problems: https://rvm.io/help and https://twitter.com/rvm_io
     
    Upgrade Notes:
     
    /Users/mac/.bash_profile:1:PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet
     
             * WARNING: Above files contains `PATH=` with no `$PATH` inside, this can break RVM,
     for details check https://github.com/rvm/rvm/issues/1351#issuecomment-10939525
     to avoid this warning prepend `$PATH`.
     
             * No new notes to display.
     
    RVM reloaded!
    

    Uninstall Ruby

  9. Uninstall all versions of Ruby:

    rvm uninstall ruby

  10. Have the rvm shell configuration loaded:

    source ~/.rvm/scripts/rvm
    type rvm | head -n 1

    Alternately, wipe out the folder and start over:

    rm -rf ~/.rvm
    curl -L https://get.rvm.io | bash -s stable

    The response should be:

    rvm is a function

    If so, try rvm get head again.

    rvm get head

    If the response is:

    -bash: rvm: command not found
    
  11. Get stable

    rvm get stable --auto-dotfiles
    

To upgrade Ruby using RVM

  1. First run:

    rvm autolibs homebrew

  2. Run:

    rvm install ruby

    The response:

    Searching for binary rubies, this might take some time.
    No binary rubies available for: osx/10.11/x86_64/ruby-2.3.1.
    Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
    Checking requirements for osx_brew.
    Installing requirements for osx_brew.
    Updating system.....
    Installing required packages: autoconf, automake, libtool, readline, libksba, openssl........
    Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
    Requirements installation successful.
    Installing Ruby from source to: /Users/mac/.rvm/rubies/ruby-2.3.1, this may take a while depending on your cpu(s)...
    ruby-2.3.1 - #downloading ruby-2.3.1, this may take a while depending on your connection...
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed
    100 13.7M  100 13.7M    0     0   320k      0  0:00:44  0:00:44 --:--:--  266k
    perl: warning: Setting locale failed.
    perl: warning: Please check that your locale settings:
    LC_ALL = (unset),
    LC_CTYPE = "en_US.utf-",
    LANG = "en_US.UTF-8"
     are supported and installed on your system.
    perl: warning: Falling back to the standard locale ("C").
    ruby-2.3.1 - #extracting ruby-2.3.1 to /Users/mac/.rvm/src/ruby-2.3.1.....
    ruby-2.3.1 - #configuring......................................................|
    ruby-2.3.1 - #post-configuration.
    ruby-2.3.1 - #compiling........................................................-
    ruby-2.3.1 - #installing.........
    ruby-2.3.1 - #making binaries executable..
    Installed rubygems 2.5.1 is newer than 2.4.8 provided with installed ruby, skipping installation, use --force to force installation.
    ruby-2.3.1 - #gemset created /Users/mac/.rvm/gems/ruby-2.3.1@global
    ruby-2.3.1 - #importing gemset /Users/mac/.rvm/gemsets/global.gems.............|
    ruby-2.3.1 - #generating global wrappers........
    ruby-2.3.1 - #gemset created /Users/mac/.rvm/gems/ruby-2.3.1
    ruby-2.3.1 - #importing gemsetfile /Users/mac/.rvm/gemsets/default.gems evaluated to empty gem list
    ruby-2.3.1 - #generating default wrappers........
    ruby-2.3.1 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
    Install of ruby-2.3.1 - #complete 
    Ruby was built without documentation, to build it run: rvm docs generate-ri
    
  3. View versions again.

  4. To install the latest stable rvm release:

    curl -ssL https://get.rvm.io | bash -s stable

    A sample response:

    Downloading https://github.com/rvm/rvm/archive/1.26.11.tar.gz
    Downloading https://github.com/rvm/rvm/releases/download/1.26.11/1.26.11.tar.gz.asc
    Found PGP signature at: 'https://github.com/rvm/rvm/releases/download/1.26.11/1.26.11.tar.gz.asc',
    but no GPG software exists to validate it, skipping.
     
    Installing RVM to /Users/wilsonmar/.rvm/
    Adding rvm PATH line to /Users/wilsonmar/.profile /Users/wilsonmar/.mkshrc /Users/wilsonmar/.bashrc /Users/wilsonmar/.zshrc.
    Adding rvm loading line to /Users/wilsonmar/.profile /Users/wilsonmar/.bash_profile /Users/wilsonmar/.zlogin.
    Installation of RVM in /Users/wilsonmar/.rvm/ is almost complete:
     
           * To start using RVM you need to run `source /Users/wilsonmar/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
     
    # Wilson Mar,
    #
    #   Thank you for using RVM!
    #   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
    #
    # ~Wayne, Michal & team.
     
    In case of problems: http://rvm.io/help and https://twitter.com/rvm_io
     
           * WARNING: You have '~/.profile' file, you might want to load it,
    to do that add the following line to '/Users/wilsonmar/.bash_profile':
     
    source ~/.profile
    
  5. Some say at this point close the terminal and open again.

Sample Ruby Tree program

Here is a Ruby script to produce a nice Unicode tree along with metadata to its left:

#!/usr/bin/env ruby
def tree_hierarchy( root, &children )
  queue = [[root,"",true]]
  [].tap do |results|
    until queue.empty?
      item,indent,last = queue.pop
      kids = children[item]
      extra = indent.empty? ? '' : last ? '└╴' : '├╴'
      results << [ indent+extra, item ]
      results << [ indent, nil ] if last and kids.empty?
      indent += last ? '  ' : '│ '
      parts = kids.map{ |k| [k,indent,false] }.reverse
      parts.first[2] = true unless parts.empty?
      queue.concat parts
    end
  end
end
def tree(dir)
  cols = tree_hierarchy(File.expand_path(dir)) do |d|
    File.directory?(d) ? Dir.chdir(d){ Dir['*'].map(&File.method(:expand_path)) } : []
  end.map do |indent,path|
    if path
      file = File.basename(path) + File.directory?(path) ? '/' : ''
      meta = `ls -lhd "#{path}"`.split(/\s+/)
      [ [indent,file].join, meta[0], meta[4], "%s %-2s %s" % meta[5..7] ]
    else
      [indent]
    end
  end
  maxs = cols.first.zip(*(cols[1..-1])).map{ |c| c.compact.map(&:length).max }
  tmpl = maxs.map.with_index{ |n,i| "%#{'-' if cols[0][i][/^\D/]}#{n}s" }.join('  ')
  cols.map{ |a| a.length==1 ? a.first : tmpl % a }
end
puts tree(ARGV.first || ".") if __FILE__==$0
   
  1. Copy and paste the above into a text editor program.
  2. Save the file named tree.rb.
  3. In a Terminal window, navigate to the folder holding the script.
  4. Mark the file as executable:

    chmod +x tree.rb

    This only needs to be done once.

  5. Run the program:

    tree.rb

    ERROR: The response:

    ./tree.rb:24:in `+': no implicit conversion of true into String (TypeError)
      from ./tree.rb:24:in `block in tree'
      from ./tree.rb:22:in `map'
      from ./tree.rb:22:in `tree'
      from ./tree.rb:35:in `<main>'
    

    http://superuser.com/users/57219/phrogz

Remove rvm

  1. Run the program which removes the rvm/ directory and all the rubies built within it:

    
    rvm repair
    rvm cleanup
    rvm implode --force
    
    Are you SURE you wish for rvm to implode?
    This will recursively remove /Users/wilsonmar/.rvm and other rvm traces?
    (anything other than 'yes' will cancel) > yes
    Removing rvm-shipped binaries (rvm-prompt, rvm, rvm-sudo rvm-shell and rvm-auto-ruby)
    Removing rvm wrappers in /Users/wilsonmar/.rvm/bin
    Hai! Removing /Users/wilsonmar/.rvm
    /Users/wilsonmar/.rvm has been removed.
     
    Note you may need to manually remove /etc/rvmrc and ~/.rvmrc if they exist still.
    Please check all .bashrc .bash_profile .profile and .zshrc for RVM source lines and delete or comment out if this was a Per-User installation.
    Also make sure to remove `rvm` group if this was a system installation.
    Finally it might help to relogin / restart if you want to have fresh environment (like for installing RVM again).
    
  2. Remove folders:

    rm -rf /usr/local/rvm
    sudo rm /etc/profile.d/rvm.sh
    sudo rm /etc/rvmrc
    sudo rm ~/.rvmrc
    
  3. Check references to rvm in files (replace vim with your favorite text editor command such as subl, code, etc.):

    vim ~/.bash_profile

    vim ~/.bashrc

    vim ~/.profile

  4. Restart Terminal sessions.

    See http://karloespiritu.com/replacing-rvm-with-rbenv-in-os-x/

Ruby apps on Mac

The programs I’ve figured out how to install using my bash script:

  • istats
  • gitlab (command line utilities)
  • ruby-jmeter
  • travis
  • rails
  • rust (language)

Resources:

This also provides instructions on installation of Ruby:

https://gorails.com/setup/osx/10.14-mojave#ruby

http://www.createdbypete.com/articles/ruby-on-rails-development-setup-for-mac-osx/

https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-16-04

http://devopspy.com/linux/install-latest-ruby-using-rbenv/

More on OSX

This is one of a series on Mac OSX: