How To Update Ruby Version In Mac

Are you still using an older version of Ruby and looking to update it to the latest version on your Mac? You’ve come to the right place! In this blog post, we will walk you through the process of updating Ruby on your Mac.

Prerequisites

Before we begin, make sure you have the following installed on your Mac:

  • Xcode Command Line Tools: It is essential to have Xcode’s command-line tools installed to compile Ruby. You can check if you have them installed by running xcode-select –install in your terminal.
  • Homebrew: Homebrew is a package manager for macOS that allows you to install various software and tools. If you haven’t installed Homebrew yet, visit https://brew.sh/ and follow the instructions.

Step 1: Install rbenv and ruby-build

We will use rbenv to manage multiple Ruby versions on our Mac. Moreover, we will also need the ruby-build plugin to install new Ruby versions. Run the following command in your terminal to install both:

brew install rbenv ruby-build

Once the installation is complete, add the following line to your .bash_profile, .zshrc, or .bashrc file (based on the shell you use):

if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi

Now, restart your terminal or run source ~/.bash_profile (or the respective file) to apply the changes.

Step 2: Install a new Ruby version

First, check the latest stable Ruby version by visiting the official Ruby website: https://www.ruby-lang.org/en/downloads/

Once you know the latest version, install it using the rbenv install command followed by the version number:

rbenv install 2.7.2

This will install Ruby 2.7.2 on your system. You can replace 2.7.2 with the version number you want to install.

Step 3: Switch to the new version

To start using the newly installed Ruby version, run the following command:

rbenv global 2.7.2

This will set Ruby 2.7.2 as the default version for your system. You can replace 2.7.2 with the version number you installed.

Step 4: Verify the new version

To ensure that you’re using the new Ruby version, run the following command:

ruby -v

If everything went well, you should see the new version number in the output.

Conclusion

That’s it! You’ve successfully updated your Ruby version on your Mac. With rbenv, you can easily switch between different Ruby versions whenever you need to. Happy coding!