How to install rbenv on Mac OS

In this tutorial, you will see how to install rbenv on Mac OS. rbenv helps us to install and manage Ruby versions on Mac.

Ruby is a dynamic, interpreted, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro “Matz” Matsumoto in Japan.

According to the creator, Ruby was influenced by Perl, Smalltalk, Eiffel, Ada, and Lisp. It supports multiple programming paradigms, including functional, object-oriented, and imperative.

Install rbenv

Use rbenv to pick a Ruby version for your application and guarantee that your development environment matches production. Put rbenv to work with Bundler for painless Ruby upgrades and bulletproof deployments.

We will be using Homebrew to install rbenv.

$ brew install rbenv

Read Also: How to install ruby with rvm on CentOS/RHEL 7/6

Set up rbenv in your shell

$ rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile:
eval "$(rbenv init -)"

Source your bash_profile

source  ~/.bash_profile

Verify installation

We can use rbenv doctor to verify installation.

$ curl -fsSL | bash
Checking for `rbenv' in PATH: /usr/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20181019)
Counting installed Ruby versions: 1 versions
Checking RubyGems settings: OK
Auditing installed plugins: OKcurl -fsSL | bash

Read Also: How to install Ruby 2.4.1 on CentOS 7

Install Ruby 2.4.1

Now after successful installation of rbenv now we will install ruby and manage ruby using rbenv.

$ rbenv install 2.4.1
ruby-build: use openssl from homebrew
Downloading ruby-2.4.1.tar.bz2...
Installing ruby-2.4.1...
ruby-build: use readline from homebrew
Installed ruby-2.4.1 to /Users/chetan/.rbenv/versions/2.4.1

Set default Ruby

After installation of ruby 2.4.1, we will set it up as default ruby version.

$ rbenv global 2.4.1

Use the above command to set ruby version globally.

$ rbenv local 2.4.1

Use the above command to application-specific ruby version.

Check Ruby Version

$ ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin18]

List Ruby Versions

This command will list all installed ruby versions.
$ rbenv versions
* 2.4.1 (set by /Users/chetan/.rbenv/version)

Now you have successfully installed ruby 2.4.1.

If you have any issue using this tutorial please feel free to comment below.


Leave a Reply

Your email address will not be published.