Updating Ruby using rbenv

PDF for offline use
Related Articles:
Related Links:

Let us know how you feel about this


0/250

last updated: 2016-09

Developers may wish to keep up to date with the most current version of Ruby, or may find it necessary to have different versions of Ruby installed on their computers for different projects. For example, there might be a Rails project that requires Ruby 1.9.3, another Rails project that requires Ruby 2.0, and then a Calabash project that requires Ruby 2.1.7. The chore of installing and switching between these different versions of Ruby can be greatly simplified using rbenv — a tool dedicated to managing different versions of Ruby. rbenv can also download and install different versions of Ruby using a plug-in called ruby-build.

The simplest way to install rbenv and ruby-build on OS X is to use Homebrew—a package manager for install and maintaining software that is not included in OS X by Apple.

This guide will cover the following topics:

  • How to install Homebrew
  • Installing rbenv and ruby-build
  • Updating Ruby and setting that to be the default

Requirements

Xamarin Test Cloud uses Ruby 2.3.1. For maximum compatibility with tests run locally and tests run in Test Cloud it is recommended that you use the same version while developing tests.

Calabash does require some knowledge of the bash prompt and Terminal. It will be necessary to update the file ~/.bash_profile.

It is necessary to have the Xcode Command Line tools installed.

Installation

Let’s install Homebrew and rbenv:

  1. Start up Terminal in OS X and type the following to install Homebrew:

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. Next update the Homebrew packages:

    $ brew update
  3. Use Homebrew to install rbenv and ruby-build:

    $ brew install rbenv ruby-build
  4. Finally, update ~/.bash_profile with the following:

    if which rbenv > /dev/null;
      then eval "$(rbenv init -)";
    fi
    export PATH="$HOME/.rbenv/bin:$PATH"

    It is necessary to restart Terminal order for the changes to ~/.bash_profile to take effect.

  5. To ensure that the bash session is properly updated and that rbenv is installed, restart Terminal, and type:

    $ rbenv
    rbenv 1.0.0
    Usage: rbenv <command> [<args>]
    
    Some useful rbenv commands are:
       commands    List all available rbenv commands
       local       Set or show the local application-specific Ruby version
       global      Set or show the global Ruby version
       shell       Set or show the shell-specific Ruby version
       install     Install a Ruby version using ruby-build
       uninstall   Uninstall a specific Ruby version
       rehash      Rehash rbenv shims (run this after installing executables)
       version     Show the current Ruby version and its origin
       versions    List all Ruby versions available to rbenv
       which       Display the full path to an executable
       whence      List all Ruby versions that contain the given executable
    
    See `rbenv help <command>' for information on a specific command.
    For full documentation, see: https://github.com/rbenv/rbenv#readme

Lets move on to update Ruby.

Updating Ruby with rbenv

Next let's discuss how to download, install, and switch to a new version of Ruby. rbenv does not support every known version of Ruby. To see the different versions of Ruby that are installed, type:

$ rbenv install –l

This will display a very long list of all Ruby versions that are available. You can filter this list to show you the most recent Ruby 2.3.x by using the following command line:

$ egrep "^\s+2\.3\.\d+$" <(rbenv install -l) | tail -1
  2.3.1

In the example above, we can see that version 2.1.7 is the most recent version of Ruby available via rbenv. We can install this version with the following command line:

$ rbenv install 2.3.1
Note: Do not install any version of Ruby less than 2.0

This will cause the requested version of Ruby to be downloaded and installed on the system. The final step is to set this version of Ruby to be the default version of Ruby to use. The following command will make it the default for the user:

$ rbenv local 2.3.1

This next command will make it the default for everybody:

$ rbenv global 2.3.1

We can confirm that we have updated Ruby with the following command line:

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

Summary

This guide discussed how to update Ruby on OS X Maverick. It showed how to install Homebrew, rbenv/ruby-build and how to use rbenv to install and then default to a new version of Ruby. If you have not already done so you may wish to read the Installing Calabash on OS X guide and install Calabash.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.