Skip to content

Instantly share code, notes, and snippets.

@mohammadkarbalaee
Created May 7, 2025 11:24
Show Gist options
  • Save mohammadkarbalaee/eca479718bec55454b57908ec7db2c75 to your computer and use it in GitHub Desktop.
Save mohammadkarbalaee/eca479718bec55454b57908ec7db2c75 to your computer and use it in GitHub Desktop.
Update Ruby

Okay, let's get your Ruby 2.6.10 updated! Since you're on a Mac, the best way to do this cleanly and manage your Ruby versions effectively is by using a Ruby version manager like rbenv.

Here's a step-by-step guide using rbenv:

1. Install rbenv and ruby-build (if you haven't already):

ruby-build is an rbenv plugin that simplifies the process of installing different Ruby versions.

  • Open your Terminal.

  • If you don't have Homebrew installed, install it first:

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

    Follow the on-screen instructions.

  • Install rbenv and ruby-build using Homebrew:

    brew update
    brew install rbenv ruby-build

2. Configure rbenv in your shell:

You need to initialize rbenv so it can intercept Ruby commands.

  • For Bash (default on older macOS versions): Add the following line to your ~/.bashrc file:

    echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc
    source ~/.bashrc
  • For Zsh (default on newer macOS versions): Add the following line to your ~/.zshrc file:

    echo 'eval "$(rbenv init - zsh)"' >> ~/.zshrc
    source ~/.zshrc
  • For other shells, check the rbenv documentation.

3. List available Ruby versions:

See which Ruby versions you can install.

rbenv install -l

4. Install a newer Ruby version:

Let's install the latest stable version, which is currently 3.4.3. You can also choose a slightly older but still supported version like 3.3.x if you prefer.

rbenv install 3.4.3

This will download and compile Ruby 3.4.3. This process might take a few minutes.

5. Set the global Ruby version:

To make Ruby 3.4.3 the default Ruby version for all your new terminal sessions and projects (unless a project-specific version is set), run:

rbenv global 3.4.3

6. Update the rbenv shims:

rbenv uses shims to intercept Ruby-related commands. After installing a new Ruby version or changing the global version, you need to update these shims.

rbenv rehash

7. Verify the updated Ruby version:

Check that your Ruby version has been updated.

ruby -v

The output should now show something like:

ruby 3.4.3 pXXX (YYYY-MM-DD revision XXXXX) [your-architecture]

8. Clean up old Ruby versions (optional):

Once you're sure the new Ruby version is working correctly, you might want to remove the old 2.6.10 version to save disk space. First, list all installed Ruby versions:

rbenv versions

Then, uninstall the old version:

rbenv uninstall 2.6.10

Important Considerations:

  • Existing Projects: If you have existing Ruby projects, they might be configured to use a specific Ruby version (often stored in a .ruby-version file in the project root). When you navigate to such a project, rbenv will automatically switch to the specified Ruby version. You might need to update the .ruby-version file in those projects if you want them to use the new global Ruby version. You can set a project-specific Ruby version with rbenv local <version>.
  • Gems: Gems installed for your old Ruby 2.6.10 will not automatically be available for the new Ruby version. You'll need to reinstall any gems your projects depend on when using the new Ruby version. It's often a good idea to regenerate your Gemfile.lock file after switching Ruby versions within a project.

By following these steps, you'll have successfully updated your Ruby version on your Mac using rbenv, which is a clean and maintainable approach. Let me know if you encounter any issues during the process!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment