29/10/2022

How to install rbenv and ruby? [MacOS]

What is rbenv?

It is a tool for Ruby version control.

Manually installing and managing Ruby in the development environment or in the production environment is very troublesome.

But with rbenv it became easy task because you can manage multiple versions of Ruby by using rbenv.

How to install rbenv?

First step, is to open the terminal and install Homebrew.


  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

It may ask you to enter your login password for sudo permission please enter it. Then it will ask you to press Enter to continue. Also it will install Xcode command line tools in the process.

You may get the error "homebrew-core is a shallow clone. To fix it run the following command. It will take few minutes to run.


git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow

The running result of the command above.

After finishing, re-run the following command


  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then use Homwbrew to install rbenv


  brew install rbenv

Add eval "$(rbenv init - bash)" to ~/.bash_profile


$ vi ~/.bash_profile 

eval "$(rbenv init - bash)"
:wq

And run ~/.bash_profile contents in your current terminal session


$ . ~/.bash_profile

Install ruby using rbenv

In the following steps we will use rbenv to install the latest version of ruby which at the time or writing this post, v3.1.2.


$ rbenv install 3.1.2

Then set active version of ruby to v3.1.2 locally in the current directory


$ rbenv local 3.1.2
$ ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin20]

This command will generate a file called .ruby-version in the current directory containing the version of ruby 3.1.2

No comments:

Post a Comment

MySQL vs PostgreSQL

What is Mysql? MySQL is the world's most popular DBMS - it is used by 39% of developers in 2019. MySQL is a fast, reliable and versa...