Question
I need to upgrade my Ruby installation from version 2.0.0 to a newer version on macOS 10.10 Yosemite. Some gems I want to use require a more recent Ruby version.
I previously installed Ruby using Homebrew. How can I update Ruby correctly and make sure my system uses the updated version instead of the older one?
Short Answer
By the end of this page, you will understand how Ruby version management works on macOS, how Homebrew installs and upgrades Ruby, why your terminal may still show an older Ruby version, and how to switch your shell to use the updated Ruby installation correctly.
Concept
Ruby on macOS can come from more than one place.
- System Ruby: The version that ships with macOS.
- Homebrew Ruby: A newer Ruby installed by Homebrew.
- Version manager Ruby: Ruby installed by tools such as
rbenvorrvm.
The important idea is that installing a newer Ruby does not automatically mean your terminal will use it. Your shell chooses which ruby executable to run based on your PATH.
PATH is an ordered list of directories. When you type ruby -v, your shell searches those directories from left to right and uses the first matching ruby executable it finds.
That means updating Ruby usually involves two parts:
- Install or upgrade Ruby
- Make sure your shell points to the correct Ruby first
This matters because many gems require newer Ruby language features, security updates, or newer standard library behavior. In real projects, using the correct Ruby version is essential for:
- installing dependencies successfully
- running Bundler
- matching a team or production environment
- avoiding build and compatibility errors
Mental Model
Think of Ruby installations like having multiple copies of the same tool in different drawers.
- One drawer is the macOS system tools drawer.
- Another drawer is the Homebrew tools drawer.
When you ask for ruby, your terminal checks drawers in a specific order. If it looks in the system drawer first, you keep getting the old Ruby even if a newer one exists in another drawer.
So updating Ruby is not only about putting a new tool in a drawer. It is also about making sure your terminal checks the right drawer first.
Syntax and Examples
Core commands
Update Homebrew itself:
brew update
Upgrade Ruby:
brew upgrade ruby
If Ruby is not currently installed through Homebrew, install it:
brew install ruby
Check which Ruby your shell is using:
which ruby
ruby -v
Check Homebrew's Ruby location:
brew --prefix ruby
Typical PATH setup
After installing Ruby with Homebrew, you often need to add its bin directory to your shell configuration.
Example:
export PATH="$(brew --prefix ruby)/bin:$PATH"
Then reload your shell:
source ~/.bash_profile
On some systems you may use a different shell config file such as ~/.bashrc or .
Step by Step Execution
Consider this example:
brew update
brew upgrade ruby
which ruby
ruby -v
Here is what happens step by step:
-
brew update- Homebrew downloads the latest package metadata.
- This lets it know what the newest available Ruby version is.
-
brew upgrade ruby- Homebrew upgrades the installed Ruby formula.
- The newer Ruby files are placed in Homebrew's installation directories.
-
which ruby- Your shell prints the path of the Ruby executable it will run.
- If you see something like
/usr/bin/ruby, you are still using macOS system Ruby. - If you see a Homebrew path, such as
/usr/local/bin/ruby, your shell is using the Homebrew version.
-
ruby -v- Ruby prints its version.
- This confirms whether the active Ruby changed.
If the version did not change, the upgrade may have succeeded but your shell is still using the old executable first.
Example fix:
PATH=
ruby
ruby -v
Real World Use Cases
Installing gems that require a newer Ruby
Many gems drop support for old Ruby versions. Updating Ruby is often necessary before running:
gem install bundler
bundle install
Running modern Rails applications
Rails projects often specify a minimum Ruby version in Gemfile or .ruby-version. If your Ruby is too old, the app will not boot.
Matching team environments
A project may require a specific Ruby version so every developer runs the same code in development, CI, and production.
Security and maintenance
Older Ruby versions eventually stop receiving updates. Newer versions often include bug fixes, performance improvements, and security patches.
Building native extensions
Some gems compile native code. Those gems may fail on outdated Ruby versions or older toolchains tied to them.
Real Codebase Usage
In real projects, developers usually do more than just run brew upgrade ruby.
Common patterns
Verify the active executable
Developers often check both the version and the path:
ruby -v
which ruby
This avoids confusion when multiple Rubies are installed.
Use a project-specific version
Teams often define a Ruby version in files like:
.ruby-versionGemfile
Example:
ruby '3.2.2'
This helps tools and developers stay aligned.
Reinstall gems after a Ruby change
When Ruby changes, some gems may need reinstalling because they were built for a different Ruby version.
Common commands:
gem install bundler
bundle install
Prefer version managers for long-term work
In real codebases, many developers use rbenv or rvm instead of relying only on Homebrew Ruby. That makes switching between project versions easier.
Common Mistakes
1. Upgrading Ruby but still using system Ruby
Broken assumption:
brew upgrade ruby
ruby -v
If ruby -v still shows the old version, your PATH is likely pointing to /usr/bin/ruby first.
How to avoid it:
which ruby
export PATH="$(brew --prefix ruby)/bin:$PATH"
2. Editing the wrong shell config file
You might add PATH changes to a file your shell does not load.
Examples include:
~/.bash_profile~/.bashrc~/.zshrc
How to avoid it:
Check which shell you are using:
echo $SHELL
Then update the correct startup file.
3. Expecting macOS system Ruby to be replaced
Comparisons
Homebrew Ruby vs System Ruby vs Version Manager
| Approach | What it is | Best for | Drawbacks |
|---|---|---|---|
| System Ruby | Ruby included with macOS | System tasks and legacy defaults | Usually outdated, should not be modified |
| Homebrew Ruby | A newer Ruby installed with Homebrew | Simple upgrade for one main Ruby version | Less convenient if you need multiple project versions |
| rbenv / rvm | Tools that manage multiple Ruby versions | Development across many Ruby projects | Extra setup and learning |
brew upgrade vs brew install
| Command | Use it when | Result |
|---|
Cheat Sheet
# Update Homebrew package data
brew update
# Install Ruby if needed
brew install ruby
# Upgrade existing Homebrew Ruby
brew upgrade ruby
# See active Ruby path
which ruby
# See active Ruby version
ruby -v
# See Homebrew Ruby install prefix
brew --prefix ruby
PATH fix
export PATH="$(brew --prefix ruby)/bin:$PATH"
Add that line to your shell config file if needed.
Key rules
- Installing Ruby is not the same as using it.
PATHdecides whichrubyruns.- Do not replace macOS system Ruby.
- Use
which rubyandruby -vtogether. - Reinstall gems if necessary after changing Ruby.
Common files
~/.bash_profile~/.bashrc~/.zshrc
Useful follow-up commands
FAQ
Why does ruby -v still show the old version after brew upgrade ruby?
Because your shell is probably still finding system Ruby first in PATH.
How do I check which Ruby my terminal is using?
Run:
which ruby
Should I replace the macOS system Ruby?
No. It is safer to leave system Ruby alone and use a separate Homebrew or version-manager installation.
Do I need to reinstall gems after updating Ruby?
Often yes, especially gems with native extensions or project dependencies managed by Bundler.
Is Homebrew enough for Ruby version management?
It is enough if you only need one main Ruby version. If you work on multiple projects with different Ruby versions, rbenv or rvm is usually better.
What shell file should I edit on macOS Yosemite?
It depends on your shell. Check with:
echo $SHELL
Then update the appropriate startup file such as ~/.bash_profile.
What is the difference between installing and upgrading Ruby?
Installing adds Ruby if it is missing. Upgrading updates an existing Homebrew Ruby to a newer version.
Mini Project
Description
Create a small Ruby environment check script and setup workflow that helps you confirm whether your Mac is using the correct Homebrew Ruby. This project is useful because version problems are common when setting up Ruby apps, and developers often need a repeatable way to verify their environment before installing gems or running a project.
Goal
Build a simple command-line check that reports the active Ruby path and version, and confirms whether Homebrew Ruby is being used.
Requirements
- Update Homebrew package information.
- Install or upgrade Ruby with Homebrew.
- Create a Ruby script that prints the current Ruby version and executable path.
- Run the script and verify whether the Ruby executable comes from Homebrew.
- If needed, update your PATH so Homebrew Ruby is used first.
Keep learning
Related questions
Calling an Overridden Monkey-Patched Method in Ruby
Learn how to call the original method when monkey patching in Ruby, including alias_method patterns, examples, pitfalls, and practical usage.
Difference Between require and include in Ruby
Learn the difference between require and include in Ruby, when to load a file, and when to mix module methods into a class.
Fixing Ruby Gem Native Extension Errors: mkmf.rb Can't Find Header Files for Ruby
Learn why Ruby gem installs fail with missing ruby.h, how native extensions work, and how to fix header file errors on Linux servers.