Skip to content

Instantly share code, notes, and snippets.

@RedenticDev
Last active February 3, 2021 10:59
Show Gist options
  • Save RedenticDev/2c71869492ba2740a3725216898c522a to your computer and use it in GitHub Desktop.
Save RedenticDev/2c71869492ba2740a3725216898c522a to your computer and use it in GitHub Desktop.
Update native Ruby installation on macOS Big Sur

Why?

Because Homebrew's Ruby cannot overwrite the system's Ruby, and you might need to update macOS native Ruby for some gems.

Prerequisite

  • Homebrew, because it can manage updates on Ruby dependencies super easily. Keep in mind that you can do without it, but that's how I did it.

Let's update

Before updating, save somewhere your installed gems, because something could go wrong, or a compatibility issue could occur, deleting all your gems. You can do it by simply running:

gem query --local

You can pipe the output into a file for example, with the > operand (Google it if you don't know how to use shell).

Then, install these packages with Homebrew:

brew install libyaml openssl

Finally, the update command:

rvm upgrade ruby <version> --with-libyaml-dir=$(brew --prefix libyaml) --with-openssl-dir=$(brew --prefix openssl)

<version> is obviously the version of Ruby you want to install. Check Ruby's site to pick a version. I personally chose 2.7.2.

In case of problems, you can rvm remove ruby and run the same command as above starting with rvm install instead of upgrade.

You can check your new version by running:

ruby -v

That's it!

Warning!

You might need to downgrade rvm if the command above doesn't work. To do so, run:

rvm get 1.27.0

This version of rvm is pretty stable AFAIK. However, it doesn't support latest versions of Ruby (3.0.0). Run again the command above after the downgrade.

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