DEV Community

Luiz Gadão
Luiz Gadão

Posted on

Easy way to change Ruby version in Mac, M1, M2 and M3

I had some problems updating and installing Ruby on my Mac, which made it difficult to configure essential tools like CocoaPods for my daily work. Here's a guide to help you change your Ruby version easily. I spent 90 minutes figuring this out, but with this guide, you should be able to set up your environment in just 5 minutes.

Step 1: Install Homebrew

If you don't have Homebrew installed on your Mac, paste this line into your terminal to install it:

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

Step 2: Install rbenv

rbenv is a simple tool to manage Ruby versions, similar to SDKMAN for Java. To install rbenv, use the following command:

brew install rbenv ruby-build
Enter fullscreen mode Exit fullscreen mode

Step 3: Initialize rbenv

To start rbenv, run:

rbenv init
Enter fullscreen mode Exit fullscreen mode

Maybe you need restart your sheel or open a new terminal window, but for me, it wasn't necessary.

Step 4: Check Your Current Ruby Version

To check your current Ruby version, use:

ruby -v
Enter fullscreen mode Exit fullscreen mode

Example output:

ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]
Enter fullscreen mode Exit fullscreen mode

Step 5: Install a Newer Ruby Version

To see the available Ruby versions, run:

rbenv install -l
Enter fullscreen mode Exit fullscreen mode

Example output:

3.1.6
3.2.4
3.3.3
jruby-9.4.7.0
mruby-3.3.0
picoruby-3.0.0
Enter fullscreen mode Exit fullscreen mode

To install and set up a newer version, for example, version 3.3.3, use:

rbenv install 3.3.3
Enter fullscreen mode Exit fullscreen mode

After donwloaded and intalled a ruby version, use:

rbenv global 3.3.3
Enter fullscreen mode Exit fullscreen mode

Step 6: Verify Your Ruby Version

Now, check your Ruby version again:

ruby -v           
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]
Enter fullscreen mode Exit fullscreen mode

If it still shows the old version, don't worry. Here's a tip:

Step 7: Update Your .zprofile

Open your .zprofile file and add the following lines:

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - zsh)"
Enter fullscreen mode Exit fullscreen mode

Save the file. To apply the changes, either open a new terminal window or reload the profile with:

source .zprofile
Enter fullscreen mode Exit fullscreen mode

Check again your ruby version, just run the command bellow and you will see the current version of Ruby in your Mac.

ruby -v
ruby 3.3.3 (2024-06-12 revision f1c7b6f435) [arm64-darwin23]
Enter fullscreen mode Exit fullscreen mode

Now your Mac is ready to install CocoaPods or any other tools you need for iOS development.
🇧🇷🧑🏻‍💻

Top comments (2)

Collapse
 
arica profile image
Arica -

This is exactly what I needed. Thanks for the guide.

Collapse
 
steven_buehler_7652635579 profile image
Steven Buehler

Before Step 6, you need to restart terminal (close current window, open new one) or reload the user profile to register any changes.