I’m currently running an older Ruby version (2.0.0) on my Mac (macOS Yosemite), and I’m starting to hit issues where certain gems won’t install or work because my Ruby version is too outdated.
I originally installed Ruby using Homebrew a while back, but I’m not sure what the best or safest way is now to update ruby version mac without breaking my existing setup. I’ve seen a few different approaches mentioned (Homebrew, version managers, etc.), and I’m a bit unsure which one is recommended these days.
What’s the proper way to upgrade Ruby to the latest stable version on macOS?
Should I stick with Homebrew, or is it better to use something like a Ruby version manager? Also, are there any precautions I should take before upgrading to avoid issues with existing projects or gems?
Any step-by-step guidance or best practices would be greatly appreciated. Thanks!
From my experience, the safest and most flexible way to update Ruby on macOS is to use a version manager like rbenv or rvm. I personally use rbenv because it’s lightweight and integrates well with macOS. The steps I usually follow are:
Set up your shell to load rbenv automatically (for example, in .zshrc or .bash_profile):
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
source ~/.zshrc
Install the latest Ruby version:
rbenv install 3.3.2 # Replace with the latest stable version
rbenv global 3.3.2
Verify:
ruby -v
This approach lets you easily switch between different Ruby versions per project without breaking existing setups, which is super handy if you’re maintaining older projects.
If you’re already comfortable with Homebrew and don’t mind replacing the system Ruby, you can update Ruby directly:
brew update
brew upgrade ruby
After that, make sure your shell PATH points to Homebrew’s Ruby first:
export PATH="/usr/local/opt/ruby/bin:$PATH"
Then check your version:
ruby -v
The downside here is that it’s a global update, so switching back to older Ruby versions isn’t as easy as with rbenv or rvm. But if you mainly need the latest version and don’t maintain old projects, this works fine.
One thing I’ve learned the hard way is to backup your gems and check project dependencies before upgrading. Using Bundler, you can freeze your current gems:
bundle lock
Or export a list:
gem list > gems_backup.txt
That way, if a newer Ruby version breaks compatibility with certain gems, you can quickly reference or reinstall them. Also, make sure to restart your terminal or IDE after updating Ruby so the changes take effect.
From my experience, I usually recommend rbenv for anyone who needs flexibility, Homebrew for quick upgrades, and always checking your gems and projects first to avoid surprises.