Ruby is a popular programming language, known for its simplicity and flexibility. It is widely used for web development and many other applications. If you’re using a Mac, chances are that you already have a version of Ruby installed. However, it might not be the latest version, which could leave you missing out on new features or improvements. In this blog post, we will guide you through the process of updating Ruby on your Mac, so you can make the most out of this powerful programming language.
Step 1: Check the current Ruby version
First, let’s find out which version of Ruby you currently have installed on your Mac. Open the Terminal application and type the following command:
This will display the currently installed Ruby version. For example:
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
If you see a similar output, it means that Ruby is already installed on your Mac.
Step 2: Install a Ruby version manager
There are several Ruby version managers available, such as RVM, asdf, and rbenv. These tools make it easy to install and manage multiple Ruby versions on your machine. For this tutorial, we’ll be using rbenv.
Installing rbenv and ruby-build
The simplest way to install rbenv and ruby-build (a plugin that provides an rbenv install command) on macOS is by using Homebrew, a popular package manager for macOS. If you haven’t installed Homebrew yet, you can follow the instructions on their official website.
Once you have Homebrew installed, open your Terminal and run the following command:
brew install rbenv ruby-build
After the installation is complete, you need to add rbenv to your shell’s initialization script. Depending on your shell, add one of the following lines to your ~/.zshrc (for Zsh) or ~/.bash_profile (for Bash) file:
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.zshrc
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
Restart your terminal to make sure the changes take effect.
Step 3: Install the latest Ruby version
Now that you have rbenv and ruby-build installed, you can easily install the latest version of Ruby. First, let’s check the available Ruby versions:
rbenv install -l
This will display a list of all available Ruby versions. Find the latest stable version (e.g., 3.0.2) and install it using the following command:
rbenv install 3.0.2
The installation might take a few minutes. Once it’s complete, set the newly installed Ruby version as the global default:
rbenv global 3.0.2
Step 4: Verify the updated Ruby version
To make sure that you’ve successfully updated Ruby on your Mac, run the following command:
You should now see the updated Ruby version in the output:
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin19]
Congratulations! You have now updated Ruby on your Mac. With this updated version, you can enjoy the latest features, performance improvements, and bug fixes. Remember that you can always use rbenv to switch between different Ruby versions or install additional ones. Happy coding!