Why You Shouldn't Use the System Ruby to Install Gems on a Mac


While Macs come preinstalled with Ruby, it’s not recommended to use this version, known as the system Ruby, to install gems.

Here are the 4 main reasons why you shouldn’t use the system Ruby to install gems on macOS, and what to do instead:

The system Ruby is old

On Monterey (macOS 12), Apple’s latest operating system, the version of Ruby that comes preinstalled is 2.6.8. This version will reach end of life at the end of March 2022. This means there won’t be any more updates and security fixes to the 2.6.x series. By contrast, the latest version of Ruby is currently 3.1.1.

The system Ruby can’t be updated

Apple includes Ruby on macOS for compatibility with legacy software. It’s not intended for consumer use, so Apple restricts access to the system Ruby. And when a new version of Ruby comes out, Apple doesn’t update Ruby within the same macOS version.

Apple will likely stop preinstalling Ruby on macOS

In the release notes for macOS Catalina, Apple mentioned it will no longer be preinstalling Ruby on macOS:

Scripting language runtimes such as Python, Ruby, and Perl are included in macOS for compatibility with legacy software. Future versions of macOS won’t include scripting language runtimes by default, and might require you to install additional packages. If your software depends on scripting languages, it’s recommended that you bundle the runtime within the app.

It’s not yet clear to me when that change will happen, but I like to stay ahead of the curve, which is why my Ruby on Mac script will still work when that happens.

Installing gems doesn’t work out of the box with the system Ruby

Unfortunately, most installation guides for gems make it seem like it’s as simple as running gem install followed by the gem name.

However, on a brand new Mac, installing any gem with gem install will result in this error:

ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory

That’s because Apple doesn’t want you messing with the system Ruby, so it doesn’t give you permissions to make changes to it.

Unfortunately, you’ll find a lot of bad advice out there to override this protection by using sudo. Learn why you should never use sudo to install gems.

There is a safe way to install gems using the system Ruby, by changing the installation path, but because the system Ruby version is so old, I don’t recommend it. And it’s not guaranteed to work for all gems.

The correct way to install Ruby gems on a Mac

The most reliable method, and the only one I recommend, is to install a separate and newer version of Ruby using a version manager.

I highly recommend using a Ruby version manager because it allows you to have multiple versions of Ruby installed at the same time, and makes it easy to switch between them. You will likely come across instructions online to install Ruby directly with Homebrew, but that will eventually confuse you because you can only use one version at a time.

Over the past ten years, I’ve helped thousands of people set up Ruby on their Mac. From clean Macs to the most obscure issues, I’ve seen and fixed it all. And the most reliable solution is to use a version manager, specifically chruby.

To help people like you, and to make it as easy and painless as possible, I built Ruby on Mac, an automated script that will set up Ruby along with other necessary development tools in minutes.

Read what people say about the script.

It doesn’t just have a one-time use. You can run it over and over to keep your system up to date and secure. And the next time you get a new Mac, it will save you half a day because it can also automatically install all your Mac apps, in addition to a complete development environment. You get all of these time savings now and in the future for a one-time cost.

When you buy Ruby on Mac today, you’ll be supporting an independent developer, and you get it at a very reasonable price given how much time it saves.

If you’re trying to set up Ruby on a work computer, you should be able to expense the one-time cost of Ruby on Mac.