How to Change Ruby Version on Mac

Hassan Ejaz Feb 02, 2024
How to Change Ruby Version on Mac

We will introduce how to change the Ruby version on Mac.

Change Ruby Version

Programming languages are updated after some interval to overcome the problems and issues that the previous version had. If we had developed any application in any programming language one year or two years ago, we want to update the application or add any new features.

There is a chance that some features in the application may not work as expected because the version of the application is older. For this purpose, we have to update the Ruby version.

There may be some chances that we may have to install a specific version of Ruby. Ruby is pre-installed on Mac.

We can use Homebrew to install the latest version of Ruby. It is open-source software.

The command to install the latest version of Ruby is shown below.

# Ruby
brew install ruby

If we want to install a specific version of Ruby, we can use the Version Manager. rbenv is the most common version manager.

First, we need to install the rbenv. We can easily install it with the help of the following command.

# Ruby
brew install rbenv

Now, we initialize the rbenv by using the command below.

# Ruby
rbenv init

After initializing, we have to close the terminal once to make the changes work. We will reopen the terminal and use the following command to install the 2.6.0 version of Ruby.

# Ruby
rbenv install 2.6.0

If we want to change the version of Ruby, we can do it by two methods. One is manually changing the .ruby-version and or using the below command.

# Ruby
rbenv local 2.6.0

But this command will only set the Ruby version but doesn’t use the version that was set. If we want to completely change the version, we use the following command.

# Ruby
rbenv local 2.6.0 && cd ~ && cd - && bundle install

Related Article - Ruby Version